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

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

Issue 10977088: Fix for Ash shortcuts unexpectedly working in system model dialog (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: impl. of review comments Created 8 years, 2 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 | « ash/accelerators/accelerator_controller.cc ('k') | ash/accelerators/accelerator_table.h » ('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/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 1002 matching lines...) Expand 10 before | Expand all | Expand 10 after
1013 #endif 1013 #endif
1014 // Others are not reserved. 1014 // Others are not reserved.
1015 EXPECT_FALSE(GetController()->IsReservedAccelerator( 1015 EXPECT_FALSE(GetController()->IsReservedAccelerator(
1016 ui::Accelerator(ui::VKEY_PRINT, ui::EF_NONE))); 1016 ui::Accelerator(ui::VKEY_PRINT, ui::EF_NONE)));
1017 EXPECT_FALSE(GetController()->IsReservedAccelerator( 1017 EXPECT_FALSE(GetController()->IsReservedAccelerator(
1018 ui::Accelerator(ui::VKEY_TAB, ui::EF_NONE))); 1018 ui::Accelerator(ui::VKEY_TAB, ui::EF_NONE)));
1019 EXPECT_FALSE(GetController()->IsReservedAccelerator( 1019 EXPECT_FALSE(GetController()->IsReservedAccelerator(
1020 ui::Accelerator(ui::VKEY_A, ui::EF_NONE))); 1020 ui::Accelerator(ui::VKEY_A, ui::EF_NONE)));
1021 } 1021 }
1022 1022
1023 TEST_F(AcceleratorControllerTest, DisallowedAtModalWindow) {
1024 std::set<AcceleratorAction> allActions;
1025 for (size_t i = 0 ; i < kAcceleratorDataLength; ++i)
1026 allActions.insert(kAcceleratorData[i].action);
1027 std::set<AcceleratorAction> actionsAllowedAtModalWindow;
1028 for (size_t k = 0 ; k < kActionsAllowedAtModalWindowLength; ++k)
1029 actionsAllowedAtModalWindow.insert(kActionsAllowedAtModalWindow[k]);
1030 for (std::set<AcceleratorAction>::const_iterator it =
1031 actionsAllowedAtModalWindow.begin();
1032 it != actionsAllowedAtModalWindow.end(); ++it) {
1033 EXPECT_FALSE(allActions.find(*it) == allActions.end())
1034 << " action from kActionsAllowedAtModalWindow"
1035 << " not found in kAcceleratorData. action: " << *it;
1036 }
1037 scoped_ptr<aura::Window> window(
1038 aura::test::CreateTestWindowWithBounds(gfx::Rect(5, 5, 20, 20), NULL));
1039 const ui::Accelerator dummy;
1040 wm::ActivateWindow(window.get());
1041 Shell::GetInstance()->SimulateModalWindowOpenForTesting(true);
1042 for (std::set<AcceleratorAction>::const_iterator it = allActions.begin();
1043 it != allActions.end(); ++it) {
1044 if (actionsAllowedAtModalWindow.find(*it) ==
1045 actionsAllowedAtModalWindow.end()) {
1046 EXPECT_TRUE(GetController()->PerformAction(*it, dummy))
1047 << " for action (disallowed at modal window): " << *it;
1048 }
1049 }
1050 #if defined(OS_CHROMEOS)
1051 // Testing of top row (F5-F10) accelerators that should still work
1052 // when a modal window is open
1053 //
1054 // Screenshot
1055 {
1056 EXPECT_TRUE(GetController()->Process(
1057 ui::Accelerator(ui::VKEY_F5, ui::EF_CONTROL_DOWN)));
1058 EXPECT_TRUE(GetController()->Process(
1059 ui::Accelerator(ui::VKEY_PRINT, ui::EF_NONE)));
1060 EXPECT_TRUE(GetController()->Process(
1061 ui::Accelerator(ui::VKEY_F5, ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN)));
1062 DummyScreenshotDelegate* delegate = new DummyScreenshotDelegate;
1063 GetController()->SetScreenshotDelegate(
1064 scoped_ptr<ScreenshotDelegate>(delegate).Pass());
1065 EXPECT_EQ(0, delegate->handle_take_screenshot_count());
1066 EXPECT_TRUE(GetController()->Process(
1067 ui::Accelerator(ui::VKEY_F5, ui::EF_CONTROL_DOWN)));
1068 EXPECT_EQ(1, delegate->handle_take_screenshot_count());
1069 EXPECT_TRUE(GetController()->Process(
1070 ui::Accelerator(ui::VKEY_PRINT, ui::EF_NONE)));
1071 EXPECT_EQ(2, delegate->handle_take_screenshot_count());
1072 EXPECT_TRUE(GetController()->Process(
1073 ui::Accelerator(ui::VKEY_F5, ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN)));
1074 EXPECT_EQ(2, delegate->handle_take_screenshot_count());
1075 }
1076 // Brightness
1077 const ui::Accelerator f6(ui::VKEY_F6, ui::EF_NONE);
1078 const ui::Accelerator f7(ui::VKEY_F7, ui::EF_NONE);
1079 {
1080 EXPECT_FALSE(GetController()->Process(f6));
1081 EXPECT_FALSE(GetController()->Process(f7));
1082 DummyBrightnessControlDelegate* delegate =
1083 new DummyBrightnessControlDelegate(true);
1084 GetController()->SetBrightnessControlDelegate(
1085 scoped_ptr<BrightnessControlDelegate>(delegate).Pass());
1086 EXPECT_FALSE(GetController()->Process(f6));
1087 EXPECT_FALSE(GetController()->Process(f7));
1088 }
1089 EnableInternalDisplay();
1090 {
1091 EXPECT_FALSE(GetController()->Process(f6));
1092 EXPECT_FALSE(GetController()->Process(f7));
1093 DummyBrightnessControlDelegate* delegate =
1094 new DummyBrightnessControlDelegate(false);
1095 GetController()->SetBrightnessControlDelegate(
1096 scoped_ptr<BrightnessControlDelegate>(delegate).Pass());
1097 EXPECT_EQ(0, delegate->handle_brightness_down_count());
1098 EXPECT_FALSE(GetController()->Process(f6));
1099 EXPECT_EQ(1, delegate->handle_brightness_down_count());
1100 EXPECT_EQ(f6, delegate->last_accelerator());
1101 EXPECT_EQ(0, delegate->handle_brightness_up_count());
1102 EXPECT_FALSE(GetController()->Process(f7));
1103 EXPECT_EQ(1, delegate->handle_brightness_up_count());
1104 EXPECT_EQ(f7, delegate->last_accelerator());
1105 }
1106 {
1107 DummyBrightnessControlDelegate* delegate =
1108 new DummyBrightnessControlDelegate(true);
1109 GetController()->SetBrightnessControlDelegate(
1110 scoped_ptr<BrightnessControlDelegate>(delegate).Pass());
1111 EXPECT_EQ(0, delegate->handle_brightness_down_count());
1112 EXPECT_TRUE(GetController()->Process(f6));
1113 EXPECT_EQ(1, delegate->handle_brightness_down_count());
1114 EXPECT_EQ(f6, delegate->last_accelerator());
1115 EXPECT_EQ(0, delegate->handle_brightness_up_count());
1116 EXPECT_TRUE(GetController()->Process(f7));
1117 EXPECT_EQ(1, delegate->handle_brightness_up_count());
1118 EXPECT_EQ(f7, delegate->last_accelerator());
1119 }
1120 // Volume
1121 const ui::Accelerator f8(ui::VKEY_F8, ui::EF_NONE);
1122 const ui::Accelerator f9(ui::VKEY_F9, ui::EF_NONE);
1123 const ui::Accelerator f10(ui::VKEY_F10, ui::EF_NONE);
1124 {
1125 EXPECT_TRUE(GetController()->Process(f8));
1126 EXPECT_TRUE(GetController()->Process(f9));
1127 EXPECT_TRUE(GetController()->Process(f10));
1128 DummyVolumeControlDelegate* delegate =
1129 new DummyVolumeControlDelegate(false);
1130 ash::Shell::GetInstance()->tray_delegate()->SetVolumeControlDelegate(
1131 scoped_ptr<VolumeControlDelegate>(delegate).Pass());
1132 EXPECT_EQ(0, delegate->handle_volume_mute_count());
1133 EXPECT_FALSE(GetController()->Process(f8));
1134 EXPECT_EQ(1, delegate->handle_volume_mute_count());
1135 EXPECT_EQ(f8, delegate->last_accelerator());
1136 EXPECT_EQ(0, delegate->handle_volume_down_count());
1137 EXPECT_FALSE(GetController()->Process(f9));
1138 EXPECT_EQ(1, delegate->handle_volume_down_count());
1139 EXPECT_EQ(f9, delegate->last_accelerator());
1140 EXPECT_EQ(0, delegate->handle_volume_up_count());
1141 EXPECT_FALSE(GetController()->Process(f10));
1142 EXPECT_EQ(1, delegate->handle_volume_up_count());
1143 EXPECT_EQ(f10, delegate->last_accelerator());
1144 }
1145 {
1146 DummyVolumeControlDelegate* delegate = new DummyVolumeControlDelegate(true);
1147 ash::Shell::GetInstance()->tray_delegate()->SetVolumeControlDelegate(
1148 scoped_ptr<VolumeControlDelegate>(delegate).Pass());
1149 EXPECT_EQ(0, delegate->handle_volume_mute_count());
1150 EXPECT_TRUE(GetController()->Process(f8));
1151 EXPECT_EQ(1, delegate->handle_volume_mute_count());
1152 EXPECT_EQ(f8, delegate->last_accelerator());
1153 EXPECT_EQ(0, delegate->handle_volume_down_count());
1154 EXPECT_TRUE(GetController()->Process(f9));
1155 EXPECT_EQ(1, delegate->handle_volume_down_count());
1156 EXPECT_EQ(f9, delegate->last_accelerator());
1157 EXPECT_EQ(0, delegate->handle_volume_up_count());
1158 EXPECT_TRUE(GetController()->Process(f10));
1159 EXPECT_EQ(1, delegate->handle_volume_up_count());
1160 EXPECT_EQ(f10, delegate->last_accelerator());
1161 }
1162 #endif
1163 }
1164
1023 } // namespace test 1165 } // namespace test
1024 } // namespace ash 1166 } // namespace ash
OLDNEW
« no previous file with comments | « ash/accelerators/accelerator_controller.cc ('k') | ash/accelerators/accelerator_table.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698