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 1017 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1028 #endif | 1028 #endif |
1029 // Others are not reserved. | 1029 // Others are not reserved. |
1030 EXPECT_FALSE(GetController()->IsReservedAccelerator( | 1030 EXPECT_FALSE(GetController()->IsReservedAccelerator( |
1031 ui::Accelerator(ui::VKEY_PRINT, ui::EF_NONE))); | 1031 ui::Accelerator(ui::VKEY_PRINT, ui::EF_NONE))); |
1032 EXPECT_FALSE(GetController()->IsReservedAccelerator( | 1032 EXPECT_FALSE(GetController()->IsReservedAccelerator( |
1033 ui::Accelerator(ui::VKEY_TAB, ui::EF_NONE))); | 1033 ui::Accelerator(ui::VKEY_TAB, ui::EF_NONE))); |
1034 EXPECT_FALSE(GetController()->IsReservedAccelerator( | 1034 EXPECT_FALSE(GetController()->IsReservedAccelerator( |
1035 ui::Accelerator(ui::VKEY_A, ui::EF_NONE))); | 1035 ui::Accelerator(ui::VKEY_A, ui::EF_NONE))); |
1036 } | 1036 } |
1037 | 1037 |
1038 TEST_F(AcceleratorControllerTest, DisallowedAtModalWindow) { | |
1039 #if defined(OS_CHROMEOS) | |
Daniel Erat
2012/10/16 23:22:29
nit: do you mind just ifdef-ing out the test itsel
sschmitz
2012/10/16 23:52:43
Done.
| |
1040 std::set<AcceleratorAction> allActions; | |
1041 for (size_t i = 0 ; i < kAcceleratorDataLength; ++i) | |
1042 allActions.insert(kAcceleratorData[i].action); | |
1043 std::set<AcceleratorAction> actionsAllowedAtModalWindow; | |
1044 for (size_t k = 0 ; k < kActionsAllowedAtModalWindowLength; ++k) | |
1045 actionsAllowedAtModalWindow.insert(kActionsAllowedAtModalWindow[k]); | |
1046 for (std::set<AcceleratorAction>::const_iterator it = | |
1047 actionsAllowedAtModalWindow.begin(); | |
1048 it != actionsAllowedAtModalWindow.end(); ++it) { | |
1049 EXPECT_FALSE(allActions.find(*it) == allActions.end()) | |
1050 << " action from kActionsAllowedAtModalWindow" | |
1051 << " not found in kAcceleratorData. action: " << *it; | |
1052 } | |
1053 scoped_ptr<aura::Window> window( | |
1054 aura::test::CreateTestWindowWithBounds(gfx::Rect(5, 5, 20, 20), NULL)); | |
1055 const ui::Accelerator dummy; | |
1056 wm::ActivateWindow(window.get()); | |
1057 Shell::GetInstance()->SimulateModalWindowOpenForTesting(true); | |
1058 for (std::set<AcceleratorAction>::const_iterator it = allActions.begin(); | |
1059 it != allActions.end(); ++it) { | |
1060 if (actionsAllowedAtModalWindow.find(*it) == | |
1061 actionsAllowedAtModalWindow.end()) { | |
1062 EXPECT_TRUE(GetController()->PerformAction(*it, dummy)) | |
1063 << " for action (disallowed at modal window): " << *it; | |
1064 } | |
1065 } | |
1066 // Testing of top row (F5-F10) accelerators that should still work | |
1067 // when a modal window is open | |
1068 // | |
1069 // Screenshot | |
1070 { | |
1071 EXPECT_TRUE(GetController()->Process( | |
1072 ui::Accelerator(ui::VKEY_F5, ui::EF_CONTROL_DOWN))); | |
1073 EXPECT_TRUE(GetController()->Process( | |
1074 ui::Accelerator(ui::VKEY_PRINT, ui::EF_NONE))); | |
1075 EXPECT_TRUE(GetController()->Process( | |
1076 ui::Accelerator(ui::VKEY_F5, ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN))); | |
1077 DummyScreenshotDelegate* delegate = new DummyScreenshotDelegate; | |
1078 GetController()->SetScreenshotDelegate( | |
1079 scoped_ptr<ScreenshotDelegate>(delegate).Pass()); | |
1080 EXPECT_EQ(0, delegate->handle_take_screenshot_count()); | |
1081 EXPECT_TRUE(GetController()->Process( | |
1082 ui::Accelerator(ui::VKEY_F5, ui::EF_CONTROL_DOWN))); | |
1083 EXPECT_EQ(1, delegate->handle_take_screenshot_count()); | |
1084 EXPECT_TRUE(GetController()->Process( | |
1085 ui::Accelerator(ui::VKEY_PRINT, ui::EF_NONE))); | |
1086 EXPECT_EQ(2, delegate->handle_take_screenshot_count()); | |
1087 EXPECT_TRUE(GetController()->Process( | |
1088 ui::Accelerator(ui::VKEY_F5, ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN))); | |
1089 EXPECT_EQ(2, delegate->handle_take_screenshot_count()); | |
1090 } | |
1091 // Brightness | |
1092 const ui::Accelerator f6(ui::VKEY_F6, ui::EF_NONE); | |
1093 const ui::Accelerator f7(ui::VKEY_F7, ui::EF_NONE); | |
1094 { | |
1095 EXPECT_FALSE(GetController()->Process(f6)); | |
1096 EXPECT_FALSE(GetController()->Process(f7)); | |
1097 DummyBrightnessControlDelegate* delegate = | |
1098 new DummyBrightnessControlDelegate(true); | |
1099 GetController()->SetBrightnessControlDelegate( | |
1100 scoped_ptr<BrightnessControlDelegate>(delegate).Pass()); | |
1101 EXPECT_FALSE(GetController()->Process(f6)); | |
1102 EXPECT_FALSE(GetController()->Process(f7)); | |
1103 } | |
1104 EnableInternalDisplay(); | |
1105 { | |
1106 EXPECT_FALSE(GetController()->Process(f6)); | |
1107 EXPECT_FALSE(GetController()->Process(f7)); | |
1108 DummyBrightnessControlDelegate* delegate = | |
1109 new DummyBrightnessControlDelegate(false); | |
1110 GetController()->SetBrightnessControlDelegate( | |
1111 scoped_ptr<BrightnessControlDelegate>(delegate).Pass()); | |
1112 EXPECT_EQ(0, delegate->handle_brightness_down_count()); | |
1113 EXPECT_FALSE(GetController()->Process(f6)); | |
1114 EXPECT_EQ(1, delegate->handle_brightness_down_count()); | |
1115 EXPECT_EQ(f6, delegate->last_accelerator()); | |
1116 EXPECT_EQ(0, delegate->handle_brightness_up_count()); | |
1117 EXPECT_FALSE(GetController()->Process(f7)); | |
1118 EXPECT_EQ(1, delegate->handle_brightness_up_count()); | |
1119 EXPECT_EQ(f7, delegate->last_accelerator()); | |
1120 } | |
1121 { | |
1122 DummyBrightnessControlDelegate* delegate = | |
1123 new DummyBrightnessControlDelegate(true); | |
1124 GetController()->SetBrightnessControlDelegate( | |
1125 scoped_ptr<BrightnessControlDelegate>(delegate).Pass()); | |
1126 EXPECT_EQ(0, delegate->handle_brightness_down_count()); | |
1127 EXPECT_TRUE(GetController()->Process(f6)); | |
1128 EXPECT_EQ(1, delegate->handle_brightness_down_count()); | |
1129 EXPECT_EQ(f6, delegate->last_accelerator()); | |
1130 EXPECT_EQ(0, delegate->handle_brightness_up_count()); | |
1131 EXPECT_TRUE(GetController()->Process(f7)); | |
1132 EXPECT_EQ(1, delegate->handle_brightness_up_count()); | |
1133 EXPECT_EQ(f7, delegate->last_accelerator()); | |
1134 } | |
1135 // Volume | |
1136 const ui::Accelerator f8(ui::VKEY_F8, ui::EF_NONE); | |
1137 const ui::Accelerator f9(ui::VKEY_F9, ui::EF_NONE); | |
1138 const ui::Accelerator f10(ui::VKEY_F10, ui::EF_NONE); | |
1139 { | |
1140 EXPECT_TRUE(GetController()->Process(f8)); | |
1141 EXPECT_TRUE(GetController()->Process(f9)); | |
1142 EXPECT_TRUE(GetController()->Process(f10)); | |
1143 DummyVolumeControlDelegate* delegate = | |
1144 new DummyVolumeControlDelegate(false); | |
1145 ash::Shell::GetInstance()->tray_delegate()->SetVolumeControlDelegate( | |
1146 scoped_ptr<VolumeControlDelegate>(delegate).Pass()); | |
1147 EXPECT_EQ(0, delegate->handle_volume_mute_count()); | |
1148 EXPECT_FALSE(GetController()->Process(f8)); | |
1149 EXPECT_EQ(1, delegate->handle_volume_mute_count()); | |
1150 EXPECT_EQ(f8, delegate->last_accelerator()); | |
1151 EXPECT_EQ(0, delegate->handle_volume_down_count()); | |
1152 EXPECT_FALSE(GetController()->Process(f9)); | |
1153 EXPECT_EQ(1, delegate->handle_volume_down_count()); | |
1154 EXPECT_EQ(f9, delegate->last_accelerator()); | |
1155 EXPECT_EQ(0, delegate->handle_volume_up_count()); | |
1156 EXPECT_FALSE(GetController()->Process(f10)); | |
1157 EXPECT_EQ(1, delegate->handle_volume_up_count()); | |
1158 EXPECT_EQ(f10, delegate->last_accelerator()); | |
1159 } | |
1160 { | |
1161 DummyVolumeControlDelegate* delegate = new DummyVolumeControlDelegate(true); | |
1162 ash::Shell::GetInstance()->tray_delegate()->SetVolumeControlDelegate( | |
1163 scoped_ptr<VolumeControlDelegate>(delegate).Pass()); | |
1164 EXPECT_EQ(0, delegate->handle_volume_mute_count()); | |
1165 EXPECT_TRUE(GetController()->Process(f8)); | |
1166 EXPECT_EQ(1, delegate->handle_volume_mute_count()); | |
1167 EXPECT_EQ(f8, delegate->last_accelerator()); | |
1168 EXPECT_EQ(0, delegate->handle_volume_down_count()); | |
1169 EXPECT_TRUE(GetController()->Process(f9)); | |
1170 EXPECT_EQ(1, delegate->handle_volume_down_count()); | |
1171 EXPECT_EQ(f9, delegate->last_accelerator()); | |
1172 EXPECT_EQ(0, delegate->handle_volume_up_count()); | |
1173 EXPECT_TRUE(GetController()->Process(f10)); | |
1174 EXPECT_EQ(1, delegate->handle_volume_up_count()); | |
1175 EXPECT_EQ(f10, delegate->last_accelerator()); | |
1176 } | |
1177 #endif | |
1178 } | |
1179 | |
1038 } // namespace test | 1180 } // namespace test |
1039 } // namespace ash | 1181 } // namespace ash |
OLD | NEW |