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/accelerators/accelerator_controller.h" | 5 #include "ash/accelerators/accelerator_controller.h" |
6 #include "ash/accelerators/accelerator_table.h" | 6 #include "ash/accelerators/accelerator_table.h" |
7 #include "ash/caps_lock_delegate.h" | 7 #include "ash/caps_lock_delegate.h" |
8 #include "ash/display/multi_display_manager.h" | 8 #include "ash/display/multi_display_manager.h" |
9 #include "ash/ime_control_delegate.h" | 9 #include "ash/ime_control_delegate.h" |
10 #include "ash/screenshot_delegate.h" | 10 #include "ash/screenshot_delegate.h" |
(...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
490 TEST_F(AcceleratorControllerTest, ControllerContext) { | 490 TEST_F(AcceleratorControllerTest, ControllerContext) { |
491 ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); | 491 ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); |
492 ui::Accelerator accelerator_a2(ui::VKEY_A, ui::EF_NONE); | 492 ui::Accelerator accelerator_a2(ui::VKEY_A, ui::EF_NONE); |
493 ui::Accelerator accelerator_b(ui::VKEY_B, ui::EF_NONE); | 493 ui::Accelerator accelerator_b(ui::VKEY_B, ui::EF_NONE); |
494 | 494 |
495 accelerator_a.set_type(ui::ET_KEY_PRESSED); | 495 accelerator_a.set_type(ui::ET_KEY_PRESSED); |
496 accelerator_a2.set_type(ui::ET_KEY_RELEASED); | 496 accelerator_a2.set_type(ui::ET_KEY_RELEASED); |
497 accelerator_b.set_type(ui::ET_KEY_PRESSED); | 497 accelerator_b.set_type(ui::ET_KEY_PRESSED); |
498 | 498 |
499 EXPECT_FALSE(GetController()->context()->repeated()); | 499 EXPECT_FALSE(GetController()->context()->repeated()); |
500 EXPECT_EQ(ui::ET_UNKNOWN, GetController()->context()->previous_event_type()); | 500 EXPECT_EQ(ui::ET_UNKNOWN, |
| 501 GetController()->context()->previous_accelerator().type()); |
501 | 502 |
502 GetController()->context()->UpdateContext(accelerator_a); | 503 GetController()->context()->UpdateContext(accelerator_a); |
503 EXPECT_FALSE(GetController()->context()->repeated()); | 504 EXPECT_FALSE(GetController()->context()->repeated()); |
504 EXPECT_EQ(ui::ET_KEY_PRESSED, | 505 EXPECT_EQ(ui::ET_UNKNOWN, |
505 GetController()->context()->previous_event_type()); | 506 GetController()->context()->previous_accelerator().type()); |
506 | 507 |
507 GetController()->context()->UpdateContext(accelerator_a2); | 508 GetController()->context()->UpdateContext(accelerator_a2); |
508 EXPECT_FALSE(GetController()->context()->repeated()); | 509 EXPECT_FALSE(GetController()->context()->repeated()); |
509 EXPECT_EQ(ui::ET_KEY_PRESSED, | 510 EXPECT_EQ(ui::ET_KEY_PRESSED, |
510 GetController()->context()->previous_event_type()); | 511 GetController()->context()->previous_accelerator().type()); |
511 | 512 |
512 GetController()->context()->UpdateContext(accelerator_a2); | 513 GetController()->context()->UpdateContext(accelerator_a2); |
513 EXPECT_TRUE(GetController()->context()->repeated()); | 514 EXPECT_TRUE(GetController()->context()->repeated()); |
514 EXPECT_EQ(ui::ET_KEY_RELEASED, | 515 EXPECT_EQ(ui::ET_KEY_RELEASED, |
515 GetController()->context()->previous_event_type()); | 516 GetController()->context()->previous_accelerator().type()); |
516 | 517 |
517 GetController()->context()->UpdateContext(accelerator_b); | 518 GetController()->context()->UpdateContext(accelerator_b); |
518 EXPECT_FALSE(GetController()->context()->repeated()); | 519 EXPECT_FALSE(GetController()->context()->repeated()); |
519 EXPECT_EQ(ui::ET_KEY_RELEASED, | 520 EXPECT_EQ(ui::ET_KEY_RELEASED, |
520 GetController()->context()->previous_event_type()); | 521 GetController()->context()->previous_accelerator().type()); |
521 } | 522 } |
522 | 523 |
523 TEST_F(AcceleratorControllerTest, SuppressToggleMaximized) { | 524 TEST_F(AcceleratorControllerTest, SuppressToggleMaximized) { |
524 scoped_ptr<aura::Window> window( | 525 scoped_ptr<aura::Window> window( |
525 aura::test::CreateTestWindowWithBounds(gfx::Rect(5, 5, 20, 20), NULL)); | 526 aura::test::CreateTestWindowWithBounds(gfx::Rect(5, 5, 20, 20), NULL)); |
526 wm::ActivateWindow(window.get()); | 527 wm::ActivateWindow(window.get()); |
527 const ui::Accelerator accelerator(ui::VKEY_A, ui::EF_NONE); | 528 const ui::Accelerator accelerator(ui::VKEY_A, ui::EF_NONE); |
528 const ui::Accelerator empty_accelerator; | 529 const ui::Accelerator empty_accelerator; |
529 | 530 |
530 // Toggling not suppressed. | 531 // Toggling not suppressed. |
(...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1023 ui::VKEY_X, | 1024 ui::VKEY_X, |
1024 ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN); | 1025 ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN); |
1025 const ReleaseAccelerator shift_alt_x(ui::VKEY_X, | 1026 const ReleaseAccelerator shift_alt_x(ui::VKEY_X, |
1026 ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN); | 1027 ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN); |
1027 | 1028 |
1028 EXPECT_FALSE(ProcessWithContext(shift_alt_press)); | 1029 EXPECT_FALSE(ProcessWithContext(shift_alt_press)); |
1029 EXPECT_FALSE(ProcessWithContext(shift_alt_x_press)); | 1030 EXPECT_FALSE(ProcessWithContext(shift_alt_x_press)); |
1030 EXPECT_FALSE(ProcessWithContext(shift_alt_x)); | 1031 EXPECT_FALSE(ProcessWithContext(shift_alt_x)); |
1031 EXPECT_FALSE(ProcessWithContext(shift_alt)); | 1032 EXPECT_FALSE(ProcessWithContext(shift_alt)); |
1032 EXPECT_EQ(2, delegate->handle_next_ime_count()); | 1033 EXPECT_EQ(2, delegate->handle_next_ime_count()); |
| 1034 |
| 1035 // But we _should_ if X is either VKEY_RETURN or VKEY_SPACE. |
| 1036 // TODO(nona|mazda): Remove this when crbug.com/139556 in a better way. |
| 1037 const ui::Accelerator shift_alt_return_press( |
| 1038 ui::VKEY_RETURN, |
| 1039 ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN); |
| 1040 const ReleaseAccelerator shift_alt_return( |
| 1041 ui::VKEY_RETURN, |
| 1042 ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN); |
| 1043 |
| 1044 EXPECT_FALSE(ProcessWithContext(shift_alt_press)); |
| 1045 EXPECT_FALSE(ProcessWithContext(shift_alt_return_press)); |
| 1046 EXPECT_FALSE(ProcessWithContext(shift_alt_return)); |
| 1047 EXPECT_TRUE(ProcessWithContext(shift_alt)); |
| 1048 EXPECT_EQ(3, delegate->handle_next_ime_count()); |
| 1049 |
| 1050 const ui::Accelerator shift_alt_space_press( |
| 1051 ui::VKEY_SPACE, |
| 1052 ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN); |
| 1053 const ReleaseAccelerator shift_alt_space( |
| 1054 ui::VKEY_SPACE, |
| 1055 ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN); |
| 1056 |
| 1057 EXPECT_FALSE(ProcessWithContext(shift_alt_press)); |
| 1058 EXPECT_FALSE(ProcessWithContext(shift_alt_space_press)); |
| 1059 EXPECT_FALSE(ProcessWithContext(shift_alt_space)); |
| 1060 EXPECT_TRUE(ProcessWithContext(shift_alt)); |
| 1061 EXPECT_EQ(4, delegate->handle_next_ime_count()); |
1033 } | 1062 } |
1034 | 1063 |
1035 #if defined(OS_CHROMEOS) | 1064 #if defined(OS_CHROMEOS) |
1036 // Test IME shortcuts again with unnormalized accelerators (Chrome OS only). | 1065 // Test IME shortcuts again with unnormalized accelerators (Chrome OS only). |
1037 { | 1066 { |
1038 const ui::Accelerator shift_alt_press(ui::VKEY_MENU, ui::EF_SHIFT_DOWN); | 1067 const ui::Accelerator shift_alt_press(ui::VKEY_MENU, ui::EF_SHIFT_DOWN); |
1039 const ReleaseAccelerator shift_alt(ui::VKEY_MENU, ui::EF_SHIFT_DOWN); | 1068 const ReleaseAccelerator shift_alt(ui::VKEY_MENU, ui::EF_SHIFT_DOWN); |
1040 const ui::Accelerator alt_shift_press(ui::VKEY_SHIFT, ui::EF_ALT_DOWN); | 1069 const ui::Accelerator alt_shift_press(ui::VKEY_SHIFT, ui::EF_ALT_DOWN); |
1041 const ReleaseAccelerator alt_shift(ui::VKEY_SHIFT, ui::EF_ALT_DOWN); | 1070 const ReleaseAccelerator alt_shift(ui::VKEY_SHIFT, ui::EF_ALT_DOWN); |
1042 | 1071 |
(...skipping 18 matching lines...) Expand all Loading... |
1061 | 1090 |
1062 EXPECT_FALSE(ProcessWithContext(shift_alt_press)); | 1091 EXPECT_FALSE(ProcessWithContext(shift_alt_press)); |
1063 EXPECT_FALSE(ProcessWithContext(shift_alt_x_press)); | 1092 EXPECT_FALSE(ProcessWithContext(shift_alt_x_press)); |
1064 EXPECT_FALSE(ProcessWithContext(shift_alt_x)); | 1093 EXPECT_FALSE(ProcessWithContext(shift_alt_x)); |
1065 EXPECT_FALSE(ProcessWithContext(shift_alt)); | 1094 EXPECT_FALSE(ProcessWithContext(shift_alt)); |
1066 EXPECT_EQ(2, delegate->handle_next_ime_count()); | 1095 EXPECT_EQ(2, delegate->handle_next_ime_count()); |
1067 } | 1096 } |
1068 #endif | 1097 #endif |
1069 } | 1098 } |
1070 | 1099 |
| 1100 // TODO(nona|mazda): Remove this when crbug.com/139556 in a better way. |
| 1101 TEST_F(AcceleratorControllerTest, ImeGlobalAcceleratorsWorkaround139556) { |
| 1102 // The workaround for crbug.com/139556 depends on the fact that we don't |
| 1103 // use Shift+Alt+Enter/Space with ET_KEY_PRESSED as an accelerator. Test it. |
| 1104 const ui::Accelerator shift_alt_return_press( |
| 1105 ui::VKEY_RETURN, |
| 1106 ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN); |
| 1107 EXPECT_FALSE(ProcessWithContext(shift_alt_return_press)); |
| 1108 const ui::Accelerator shift_alt_space_press( |
| 1109 ui::VKEY_SPACE, |
| 1110 ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN); |
| 1111 EXPECT_FALSE(ProcessWithContext(shift_alt_space_press)); |
| 1112 } |
| 1113 |
1071 TEST_F(AcceleratorControllerTest, ReservedAccelerators) { | 1114 TEST_F(AcceleratorControllerTest, ReservedAccelerators) { |
1072 // (Shift+)Alt+Tab and Chrome OS top-row keys are reserved. | 1115 // (Shift+)Alt+Tab and Chrome OS top-row keys are reserved. |
1073 EXPECT_TRUE(GetController()->IsReservedAccelerator( | 1116 EXPECT_TRUE(GetController()->IsReservedAccelerator( |
1074 ui::Accelerator(ui::VKEY_TAB, ui::EF_ALT_DOWN))); | 1117 ui::Accelerator(ui::VKEY_TAB, ui::EF_ALT_DOWN))); |
1075 EXPECT_TRUE(GetController()->IsReservedAccelerator( | 1118 EXPECT_TRUE(GetController()->IsReservedAccelerator( |
1076 ui::Accelerator(ui::VKEY_TAB, ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN))); | 1119 ui::Accelerator(ui::VKEY_TAB, ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN))); |
1077 #if defined(OS_CHROMEOS) | 1120 #if defined(OS_CHROMEOS) |
1078 EXPECT_TRUE(GetController()->IsReservedAccelerator( | 1121 EXPECT_TRUE(GetController()->IsReservedAccelerator( |
1079 ui::Accelerator(ui::VKEY_POWER, ui::EF_NONE))); | 1122 ui::Accelerator(ui::VKEY_POWER, ui::EF_NONE))); |
1080 #endif | 1123 #endif |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1223 EXPECT_EQ(f9, delegate->last_accelerator()); | 1266 EXPECT_EQ(f9, delegate->last_accelerator()); |
1224 EXPECT_EQ(0, delegate->handle_volume_up_count()); | 1267 EXPECT_EQ(0, delegate->handle_volume_up_count()); |
1225 EXPECT_TRUE(ProcessWithContext(f10)); | 1268 EXPECT_TRUE(ProcessWithContext(f10)); |
1226 EXPECT_EQ(1, delegate->handle_volume_up_count()); | 1269 EXPECT_EQ(1, delegate->handle_volume_up_count()); |
1227 EXPECT_EQ(f10, delegate->last_accelerator()); | 1270 EXPECT_EQ(f10, delegate->last_accelerator()); |
1228 } | 1271 } |
1229 } | 1272 } |
1230 #endif | 1273 #endif |
1231 | 1274 |
1232 } // namespace ash | 1275 } // namespace ash |
OLD | NEW |