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

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

Issue 1414483011: Deprecate Shift+Alt to switch IME and use Ctrl+Shift+Space instead. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: ensure no line breaks in the middle of shortcuts texts Created 5 years, 1 month 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
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/accelerators/accelerator_controller.h" 5 #include "ash/accelerators/accelerator_controller.h"
6 6
7 #include "ash/accelerators/accelerator_table.h" 7 #include "ash/accelerators/accelerator_table.h"
8 #include "ash/accessibility_delegate.h" 8 #include "ash/accessibility_delegate.h"
9 #include "ash/ash_switches.h" 9 #include "ash/ash_switches.h"
10 #include "ash/display/display_manager.h" 10 #include "ash/display/display_manager.h"
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 ~AcceleratorControllerTest() override {} 223 ~AcceleratorControllerTest() override {}
224 224
225 protected: 225 protected:
226 void EnableInternalDisplay() { 226 void EnableInternalDisplay() {
227 test::DisplayManagerTestApi().SetFirstDisplayAsInternalDisplay(); 227 test::DisplayManagerTestApi().SetFirstDisplayAsInternalDisplay();
228 } 228 }
229 229
230 static AcceleratorController* GetController(); 230 static AcceleratorController* GetController();
231 231
232 static bool ProcessInController(const ui::Accelerator& accelerator) { 232 static bool ProcessInController(const ui::Accelerator& accelerator) {
233 if (accelerator.type() == ui::ET_KEY_RELEASED) {
234 // If the |accelerator| should trigger on release, then we store the
235 // pressed version of it first in history then the released one to
236 // simulate what happens in reality.
237 ui::Accelerator pressed_accelerator = accelerator;
238 pressed_accelerator.set_type(ui::ET_KEY_PRESSED);
239 GetController()->accelerator_history()->StoreCurrentAccelerator(
240 pressed_accelerator);
241 }
233 GetController()->accelerator_history()-> 242 GetController()->accelerator_history()->
234 StoreCurrentAccelerator(accelerator); 243 StoreCurrentAccelerator(accelerator);
235 return GetController()->Process(accelerator); 244 return GetController()->Process(accelerator);
236 } 245 }
237 246
238 static const ui::Accelerator& GetPreviousAccelerator() { 247 static const ui::Accelerator& GetPreviousAccelerator() {
239 return GetController()->accelerator_history()-> 248 return GetController()->accelerator_history()->
240 previous_accelerator(); 249 previous_accelerator();
241 } 250 }
242 251
(...skipping 845 matching lines...) Expand 10 before | Expand all | Expand 10 after
1088 // released. 1097 // released.
1089 const ui::Accelerator shift_alt_x_press( 1098 const ui::Accelerator shift_alt_x_press(
1090 ui::VKEY_X, 1099 ui::VKEY_X,
1091 ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN); 1100 ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN);
1092 const ReleaseAccelerator shift_alt_x(ui::VKEY_X, 1101 const ReleaseAccelerator shift_alt_x(ui::VKEY_X,
1093 ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN); 1102 ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN);
1094 1103
1095 EXPECT_FALSE(ProcessInController(shift_alt_press)); 1104 EXPECT_FALSE(ProcessInController(shift_alt_press));
1096 EXPECT_FALSE(ProcessInController(shift_alt_x_press)); 1105 EXPECT_FALSE(ProcessInController(shift_alt_x_press));
1097 EXPECT_FALSE(ProcessInController(shift_alt_x)); 1106 EXPECT_FALSE(ProcessInController(shift_alt_x));
1098 EXPECT_FALSE(ProcessInController(shift_alt)); 1107 EXPECT_TRUE(ProcessInController(shift_alt));
1099 EXPECT_EQ(2, delegate->handle_next_ime_count()); 1108 EXPECT_EQ(3, delegate->handle_next_ime_count());
1100 1109
1101 // But we _should_ if X is either VKEY_RETURN or VKEY_SPACE. 1110 // But we _should_ if X is either VKEY_RETURN or VKEY_SPACE.
1102 // TODO(nona|mazda): Remove this when crbug.com/139556 in a better way. 1111 // TODO(nona|mazda): Remove this when crbug.com/139556 in a better way.
1103 const ui::Accelerator shift_alt_return_press( 1112 const ui::Accelerator shift_alt_return_press(
1104 ui::VKEY_RETURN, 1113 ui::VKEY_RETURN,
1105 ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN); 1114 ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN);
1106 const ReleaseAccelerator shift_alt_return( 1115 const ReleaseAccelerator shift_alt_return(
1107 ui::VKEY_RETURN, 1116 ui::VKEY_RETURN,
1108 ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN); 1117 ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN);
1109 1118
1110 EXPECT_FALSE(ProcessInController(shift_alt_press)); 1119 EXPECT_FALSE(ProcessInController(shift_alt_press));
1111 EXPECT_FALSE(ProcessInController(shift_alt_return_press)); 1120 EXPECT_FALSE(ProcessInController(shift_alt_return_press));
1112 EXPECT_FALSE(ProcessInController(shift_alt_return)); 1121 EXPECT_FALSE(ProcessInController(shift_alt_return));
1113 EXPECT_TRUE(ProcessInController(shift_alt)); 1122 EXPECT_TRUE(ProcessInController(shift_alt));
1114 EXPECT_EQ(3, delegate->handle_next_ime_count()); 1123 EXPECT_EQ(4, delegate->handle_next_ime_count());
1115 1124
1116 const ui::Accelerator shift_alt_space_press( 1125 const ui::Accelerator shift_alt_space_press(
1117 ui::VKEY_SPACE, 1126 ui::VKEY_SPACE,
1118 ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN); 1127 ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN);
1119 const ReleaseAccelerator shift_alt_space( 1128 const ReleaseAccelerator shift_alt_space(
1120 ui::VKEY_SPACE, 1129 ui::VKEY_SPACE,
1121 ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN); 1130 ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN);
1122 1131
1123 EXPECT_FALSE(ProcessInController(shift_alt_press)); 1132 EXPECT_FALSE(ProcessInController(shift_alt_press));
1124 EXPECT_FALSE(ProcessInController(shift_alt_space_press)); 1133 EXPECT_FALSE(ProcessInController(shift_alt_space_press));
1125 EXPECT_FALSE(ProcessInController(shift_alt_space)); 1134 EXPECT_FALSE(ProcessInController(shift_alt_space));
1126 EXPECT_TRUE(ProcessInController(shift_alt)); 1135 EXPECT_TRUE(ProcessInController(shift_alt));
1127 EXPECT_EQ(4, delegate->handle_next_ime_count()); 1136 EXPECT_EQ(5, delegate->handle_next_ime_count());
1128 } 1137 }
1129 1138
1130 #if defined(OS_CHROMEOS) 1139 #if defined(OS_CHROMEOS)
1131 // Test IME shortcuts again with unnormalized accelerators (Chrome OS only). 1140 // Test IME shortcuts again with unnormalized accelerators (Chrome OS only).
1132 { 1141 {
1133 const ui::Accelerator shift_alt_press(ui::VKEY_MENU, ui::EF_SHIFT_DOWN); 1142 const ui::Accelerator shift_alt_press(ui::VKEY_MENU, ui::EF_SHIFT_DOWN);
1134 const ReleaseAccelerator shift_alt(ui::VKEY_MENU, ui::EF_SHIFT_DOWN); 1143 const ReleaseAccelerator shift_alt(ui::VKEY_MENU, ui::EF_SHIFT_DOWN);
1135 const ui::Accelerator alt_shift_press(ui::VKEY_SHIFT, ui::EF_ALT_DOWN); 1144 const ui::Accelerator alt_shift_press(ui::VKEY_SHIFT, ui::EF_ALT_DOWN);
1136 const ReleaseAccelerator alt_shift(ui::VKEY_SHIFT, ui::EF_ALT_DOWN); 1145 const ReleaseAccelerator alt_shift(ui::VKEY_SHIFT, ui::EF_ALT_DOWN);
1137 1146
(...skipping 12 matching lines...) Expand all
1150 // released. 1159 // released.
1151 const ui::Accelerator shift_alt_x_press( 1160 const ui::Accelerator shift_alt_x_press(
1152 ui::VKEY_X, 1161 ui::VKEY_X,
1153 ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN); 1162 ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN);
1154 const ReleaseAccelerator shift_alt_x(ui::VKEY_X, 1163 const ReleaseAccelerator shift_alt_x(ui::VKEY_X,
1155 ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN); 1164 ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN);
1156 1165
1157 EXPECT_FALSE(ProcessInController(shift_alt_press)); 1166 EXPECT_FALSE(ProcessInController(shift_alt_press));
1158 EXPECT_FALSE(ProcessInController(shift_alt_x_press)); 1167 EXPECT_FALSE(ProcessInController(shift_alt_x_press));
1159 EXPECT_FALSE(ProcessInController(shift_alt_x)); 1168 EXPECT_FALSE(ProcessInController(shift_alt_x));
1160 EXPECT_FALSE(ProcessInController(shift_alt)); 1169 EXPECT_TRUE(ProcessInController(shift_alt));
1161 EXPECT_EQ(2, delegate->handle_next_ime_count()); 1170 EXPECT_EQ(3, delegate->handle_next_ime_count());
1162 } 1171 }
1163 #endif 1172 #endif
1164 } 1173 }
1165 1174
1166 // TODO(nona|mazda): Remove this when crbug.com/139556 in a better way. 1175 // TODO(nona|mazda): Remove this when crbug.com/139556 in a better way.
1167 TEST_F(AcceleratorControllerTest, ImeGlobalAcceleratorsWorkaround139556) { 1176 TEST_F(AcceleratorControllerTest, ImeGlobalAcceleratorsWorkaround139556) {
1168 // The workaround for crbug.com/139556 depends on the fact that we don't 1177 // The workaround for crbug.com/139556 depends on the fact that we don't
1169 // use Shift+Alt+Enter/Space with ET_KEY_PRESSED as an accelerator. Test it. 1178 // use Shift+Alt+Enter/Space with ET_KEY_PRESSED as an accelerator. Test it.
1170 const ui::Accelerator shift_alt_return_press( 1179 const ui::Accelerator shift_alt_return_press(
1171 ui::VKEY_RETURN, 1180 ui::VKEY_RETURN,
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
1473 1482
1474 #if defined(OS_CHROMEOS) 1483 #if defined(OS_CHROMEOS)
1475 namespace { 1484 namespace {
1476 1485
1477 // defines a class to test the behavior of deprecated accelerators. 1486 // defines a class to test the behavior of deprecated accelerators.
1478 class DeprecatedAcceleratorTester : public AcceleratorControllerTest { 1487 class DeprecatedAcceleratorTester : public AcceleratorControllerTest {
1479 public: 1488 public:
1480 DeprecatedAcceleratorTester() {} 1489 DeprecatedAcceleratorTester() {}
1481 ~DeprecatedAcceleratorTester() override {} 1490 ~DeprecatedAcceleratorTester() override {}
1482 1491
1492 void SetUp() override {
1493 AcceleratorControllerTest::SetUp();
1494
1495 // For testing the deprecated and new IME shortcuts.
1496 DummyImeControlDelegate* delegate = new DummyImeControlDelegate;
1497 GetController()->SetImeControlDelegate(
1498 scoped_ptr<ImeControlDelegate>(delegate).Pass());
1499 }
1500
1483 ui::Accelerator CreateAccelerator(const AcceleratorData& data) const { 1501 ui::Accelerator CreateAccelerator(const AcceleratorData& data) const {
1484 ui::Accelerator result(data.keycode, data.modifiers); 1502 ui::Accelerator result(data.keycode, data.modifiers);
1485 result.set_type(data.trigger_on_press ? ui::ET_KEY_PRESSED 1503 result.set_type(data.trigger_on_press ? ui::ET_KEY_PRESSED
1486 : ui::ET_KEY_RELEASED); 1504 : ui::ET_KEY_RELEASED);
1487 return result; 1505 return result;
1488 } 1506 }
1489 1507
1490 void ResetStateIfNeeded() { 1508 void ResetStateIfNeeded() {
1491 Shell* shell = Shell::GetInstance(); 1509 Shell* shell = Shell::GetInstance();
1492 if (shell->session_state_delegate()->IsScreenLocked() || 1510 if (shell->session_state_delegate()->IsScreenLocked() ||
(...skipping 19 matching lines...) Expand all
1512 } 1530 }
1513 1531
1514 private: 1532 private:
1515 DISALLOW_COPY_AND_ASSIGN(DeprecatedAcceleratorTester); 1533 DISALLOW_COPY_AND_ASSIGN(DeprecatedAcceleratorTester);
1516 }; 1534 };
1517 1535
1518 } // namespace 1536 } // namespace
1519 1537
1520 TEST_F(DeprecatedAcceleratorTester, TestDeprecatedAcceleratorsBehavior) { 1538 TEST_F(DeprecatedAcceleratorTester, TestDeprecatedAcceleratorsBehavior) {
1521 for (size_t i = 0; i < kDeprecatedAcceleratorsLength; ++i) { 1539 for (size_t i = 0; i < kDeprecatedAcceleratorsLength; ++i) {
1522 const DeprecatedAcceleratorData& data = kDeprecatedAccelerators[i]; 1540 const AcceleratorData& entry = kDeprecatedAccelerators[i];
1541
1542 auto itr = GetController()->actions_with_deprecations_.find(entry.action);
1543 ASSERT_TRUE(itr != GetController()->actions_with_deprecations_.end());
1544 const DeprecatedAcceleratorData* data = itr->second;
1523 1545
1524 EXPECT_TRUE(IsMessageCenterEmpty()); 1546 EXPECT_TRUE(IsMessageCenterEmpty());
1525 1547 ui::Accelerator deprecated_accelerator = CreateAccelerator(entry);
1526 ui::Accelerator deprecated_accelerator = 1548 if (data->deprecated_enabled)
1527 CreateAccelerator(data.deprecated_accelerator);
1528 if (data.deprecated_enabled)
1529 EXPECT_TRUE(ProcessInController(deprecated_accelerator)); 1549 EXPECT_TRUE(ProcessInController(deprecated_accelerator));
1530 else 1550 else
1531 EXPECT_FALSE(ProcessInController(deprecated_accelerator)); 1551 EXPECT_FALSE(ProcessInController(deprecated_accelerator));
1532 1552
1533 // We expect to see a notification in the message center. 1553 // We expect to see a notification in the message center.
1534 EXPECT_TRUE( 1554 EXPECT_TRUE(
1535 ContainsDeprecatedAcceleratorNotification(data.uma_histogram_name)); 1555 ContainsDeprecatedAcceleratorNotification(data->uma_histogram_name));
1536 RemoveAllNotifications(); 1556 RemoveAllNotifications();
1537 1557
1538 // If the action is LOCK_SCREEN, we must reset the state by unlocking the 1558 // If the action is LOCK_SCREEN, we must reset the state by unlocking the
1539 // screen before we proceed testing the rest of accelerators. 1559 // screen before we proceed testing the rest of accelerators.
1540 ResetStateIfNeeded(); 1560 ResetStateIfNeeded();
1541 } 1561 }
1542 } 1562 }
1543 1563
1544 TEST_F(DeprecatedAcceleratorTester, TestNewAccelerators) { 1564 TEST_F(DeprecatedAcceleratorTester, TestNewAccelerators) {
1545 // Add below the new accelerators that replaced the deprecated ones (if any). 1565 // Add below the new accelerators that replaced the deprecated ones (if any).
1546 const AcceleratorData kNewAccelerators[] = { 1566 const AcceleratorData kNewAccelerators[] = {
1547 {true, ui::VKEY_L, ui::EF_COMMAND_DOWN, LOCK_SCREEN}, 1567 {true, ui::VKEY_L, ui::EF_COMMAND_DOWN, LOCK_SCREEN},
1568 {true, ui::VKEY_SPACE, ui::EF_CONTROL_DOWN | ui::EF_SHIFT_DOWN, NEXT_IME},
1548 {true, ui::VKEY_ESCAPE, ui::EF_COMMAND_DOWN, SHOW_TASK_MANAGER}, 1569 {true, ui::VKEY_ESCAPE, ui::EF_COMMAND_DOWN, SHOW_TASK_MANAGER},
1549 }; 1570 };
1550 1571
1551 EXPECT_TRUE(IsMessageCenterEmpty()); 1572 EXPECT_TRUE(IsMessageCenterEmpty());
1552 1573
1553 for (auto data : kNewAccelerators) { 1574 for (auto data : kNewAccelerators) {
1554 EXPECT_TRUE(ProcessInController(CreateAccelerator(data))); 1575 EXPECT_TRUE(ProcessInController(CreateAccelerator(data)));
1555 1576
1556 // Expect no notifications from the new accelerators. 1577 // Expect no notifications from the new accelerators.
1557 EXPECT_TRUE(IsMessageCenterEmpty()); 1578 EXPECT_TRUE(IsMessageCenterEmpty());
1558 1579
1559 // If the action is LOCK_SCREEN, we must reset the state by unlocking the 1580 // If the action is LOCK_SCREEN, we must reset the state by unlocking the
1560 // screen before we proceed testing the rest of accelerators. 1581 // screen before we proceed testing the rest of accelerators.
1561 ResetStateIfNeeded(); 1582 ResetStateIfNeeded();
1562 } 1583 }
1563 } 1584 }
1564 #endif // defined(OS_CHROMEOS) 1585 #endif // defined(OS_CHROMEOS)
1565 1586
1566 } // namespace ash 1587 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698