| 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 | |
| 7 #include "ash/accelerators/accelerator_table.h" | 6 #include "ash/accelerators/accelerator_table.h" |
| 8 #include "ash/accessibility_delegate.h" | 7 #include "ash/accessibility_delegate.h" |
| 9 #include "ash/ash_switches.h" | 8 #include "ash/ash_switches.h" |
| 10 #include "ash/display/display_manager.h" | 9 #include "ash/display/display_manager.h" |
| 11 #include "ash/ime_control_delegate.h" | 10 #include "ash/ime_control_delegate.h" |
| 12 #include "ash/screen_util.h" | 11 #include "ash/screen_util.h" |
| 13 #include "ash/shell.h" | 12 #include "ash/shell.h" |
| 14 #include "ash/shell_window_ids.h" | 13 #include "ash/shell_window_ids.h" |
| 15 #include "ash/system/brightness_control_delegate.h" | 14 #include "ash/system/brightness_control_delegate.h" |
| 16 #include "ash/system/keyboard_brightness/keyboard_brightness_control_delegate.h" | 15 #include "ash/system/keyboard_brightness/keyboard_brightness_control_delegate.h" |
| 17 #include "ash/system/tray/system_tray_delegate.h" | 16 #include "ash/system/tray/system_tray_delegate.h" |
| 18 #include "ash/test/ash_test_base.h" | 17 #include "ash/test/ash_test_base.h" |
| 19 #include "ash/test/display_manager_test_api.h" | 18 #include "ash/test/display_manager_test_api.h" |
| 20 #include "ash/test/test_screenshot_delegate.h" | 19 #include "ash/test/test_screenshot_delegate.h" |
| 21 #include "ash/test/test_shell_delegate.h" | 20 #include "ash/test/test_shell_delegate.h" |
| 22 #include "ash/test/test_volume_control_delegate.h" | |
| 23 #include "ash/volume_control_delegate.h" | 21 #include "ash/volume_control_delegate.h" |
| 24 #include "ash/wm/window_state.h" | 22 #include "ash/wm/window_state.h" |
| 25 #include "ash/wm/window_util.h" | 23 #include "ash/wm/window_util.h" |
| 26 #include "base/command_line.h" | 24 #include "base/command_line.h" |
| 27 #include "ui/aura/test/test_window_delegate.h" | 25 #include "ui/aura/test/test_window_delegate.h" |
| 28 #include "ui/aura/test/test_windows.h" | 26 #include "ui/aura/test/test_windows.h" |
| 29 #include "ui/aura/window.h" | 27 #include "ui/aura/window.h" |
| 30 #include "ui/events/event.h" | 28 #include "ui/events/event.h" |
| 31 #include "ui/events/event_processor.h" | 29 #include "ui/events/event_processor.h" |
| 32 #include "ui/gfx/screen.h" | 30 #include "ui/gfx/screen.h" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 }; | 62 }; |
| 65 | 63 |
| 66 class ReleaseAccelerator : public ui::Accelerator { | 64 class ReleaseAccelerator : public ui::Accelerator { |
| 67 public: | 65 public: |
| 68 ReleaseAccelerator(ui::KeyboardCode keycode, int modifiers) | 66 ReleaseAccelerator(ui::KeyboardCode keycode, int modifiers) |
| 69 : ui::Accelerator(keycode, modifiers) { | 67 : ui::Accelerator(keycode, modifiers) { |
| 70 set_type(ui::ET_KEY_RELEASED); | 68 set_type(ui::ET_KEY_RELEASED); |
| 71 } | 69 } |
| 72 }; | 70 }; |
| 73 | 71 |
| 72 class DummyVolumeControlDelegate : public VolumeControlDelegate { |
| 73 public: |
| 74 explicit DummyVolumeControlDelegate(bool consume) |
| 75 : consume_(consume), |
| 76 handle_volume_mute_count_(0), |
| 77 handle_volume_down_count_(0), |
| 78 handle_volume_up_count_(0) { |
| 79 } |
| 80 virtual ~DummyVolumeControlDelegate() {} |
| 81 |
| 82 virtual bool HandleVolumeMute(const ui::Accelerator& accelerator) OVERRIDE { |
| 83 ++handle_volume_mute_count_; |
| 84 last_accelerator_ = accelerator; |
| 85 return consume_; |
| 86 } |
| 87 virtual bool HandleVolumeDown(const ui::Accelerator& accelerator) OVERRIDE { |
| 88 ++handle_volume_down_count_; |
| 89 last_accelerator_ = accelerator; |
| 90 return consume_; |
| 91 } |
| 92 virtual bool HandleVolumeUp(const ui::Accelerator& accelerator) OVERRIDE { |
| 93 ++handle_volume_up_count_; |
| 94 last_accelerator_ = accelerator; |
| 95 return consume_; |
| 96 } |
| 97 |
| 98 int handle_volume_mute_count() const { |
| 99 return handle_volume_mute_count_; |
| 100 } |
| 101 int handle_volume_down_count() const { |
| 102 return handle_volume_down_count_; |
| 103 } |
| 104 int handle_volume_up_count() const { |
| 105 return handle_volume_up_count_; |
| 106 } |
| 107 const ui::Accelerator& last_accelerator() const { |
| 108 return last_accelerator_; |
| 109 } |
| 110 |
| 111 private: |
| 112 const bool consume_; |
| 113 int handle_volume_mute_count_; |
| 114 int handle_volume_down_count_; |
| 115 int handle_volume_up_count_; |
| 116 ui::Accelerator last_accelerator_; |
| 117 |
| 118 DISALLOW_COPY_AND_ASSIGN(DummyVolumeControlDelegate); |
| 119 }; |
| 120 |
| 74 class DummyBrightnessControlDelegate : public BrightnessControlDelegate { | 121 class DummyBrightnessControlDelegate : public BrightnessControlDelegate { |
| 75 public: | 122 public: |
| 76 explicit DummyBrightnessControlDelegate(bool consume) | 123 explicit DummyBrightnessControlDelegate(bool consume) |
| 77 : consume_(consume), | 124 : consume_(consume), |
| 78 handle_brightness_down_count_(0), | 125 handle_brightness_down_count_(0), |
| 79 handle_brightness_up_count_(0) { | 126 handle_brightness_up_count_(0) { |
| 80 } | 127 } |
| 81 virtual ~DummyBrightnessControlDelegate() {} | 128 virtual ~DummyBrightnessControlDelegate() {} |
| 82 | 129 |
| 83 virtual bool HandleBrightnessDown( | 130 virtual bool HandleBrightnessDown( |
| (...skipping 576 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 660 EXPECT_TRUE(ProcessWithContext( | 707 EXPECT_TRUE(ProcessWithContext( |
| 661 ui::Accelerator(ui::VKEY_MEDIA_LAUNCH_APP1, | 708 ui::Accelerator(ui::VKEY_MEDIA_LAUNCH_APP1, |
| 662 ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN))); | 709 ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN))); |
| 663 EXPECT_EQ(2, delegate->handle_take_screenshot_count()); | 710 EXPECT_EQ(2, delegate->handle_take_screenshot_count()); |
| 664 } | 711 } |
| 665 #endif | 712 #endif |
| 666 const ui::Accelerator volume_mute(ui::VKEY_VOLUME_MUTE, ui::EF_NONE); | 713 const ui::Accelerator volume_mute(ui::VKEY_VOLUME_MUTE, ui::EF_NONE); |
| 667 const ui::Accelerator volume_down(ui::VKEY_VOLUME_DOWN, ui::EF_NONE); | 714 const ui::Accelerator volume_down(ui::VKEY_VOLUME_DOWN, ui::EF_NONE); |
| 668 const ui::Accelerator volume_up(ui::VKEY_VOLUME_UP, ui::EF_NONE); | 715 const ui::Accelerator volume_up(ui::VKEY_VOLUME_UP, ui::EF_NONE); |
| 669 { | 716 { |
| 670 TestVolumeControlDelegate* delegate = | 717 DummyVolumeControlDelegate* delegate = |
| 671 new TestVolumeControlDelegate(false); | 718 new DummyVolumeControlDelegate(false); |
| 672 ash::Shell::GetInstance()->system_tray_delegate()->SetVolumeControlDelegate( | 719 ash::Shell::GetInstance()->system_tray_delegate()->SetVolumeControlDelegate( |
| 673 scoped_ptr<VolumeControlDelegate>(delegate).Pass()); | 720 scoped_ptr<VolumeControlDelegate>(delegate).Pass()); |
| 674 EXPECT_EQ(0, delegate->handle_volume_mute_count()); | 721 EXPECT_EQ(0, delegate->handle_volume_mute_count()); |
| 675 EXPECT_FALSE(ProcessWithContext(volume_mute)); | 722 EXPECT_FALSE(ProcessWithContext(volume_mute)); |
| 676 EXPECT_EQ(1, delegate->handle_volume_mute_count()); | 723 EXPECT_EQ(1, delegate->handle_volume_mute_count()); |
| 677 EXPECT_EQ(volume_mute, delegate->last_accelerator()); | 724 EXPECT_EQ(volume_mute, delegate->last_accelerator()); |
| 678 EXPECT_EQ(0, delegate->handle_volume_down_count()); | 725 EXPECT_EQ(0, delegate->handle_volume_down_count()); |
| 679 EXPECT_FALSE(ProcessWithContext(volume_down)); | 726 EXPECT_FALSE(ProcessWithContext(volume_down)); |
| 680 EXPECT_EQ(1, delegate->handle_volume_down_count()); | 727 EXPECT_EQ(1, delegate->handle_volume_down_count()); |
| 681 EXPECT_EQ(volume_down, delegate->last_accelerator()); | 728 EXPECT_EQ(volume_down, delegate->last_accelerator()); |
| 682 EXPECT_EQ(0, delegate->handle_volume_up_count()); | 729 EXPECT_EQ(0, delegate->handle_volume_up_count()); |
| 683 EXPECT_FALSE(ProcessWithContext(volume_up)); | 730 EXPECT_FALSE(ProcessWithContext(volume_up)); |
| 684 EXPECT_EQ(1, delegate->handle_volume_up_count()); | 731 EXPECT_EQ(1, delegate->handle_volume_up_count()); |
| 685 EXPECT_EQ(volume_up, delegate->last_accelerator()); | 732 EXPECT_EQ(volume_up, delegate->last_accelerator()); |
| 686 } | 733 } |
| 687 { | 734 { |
| 688 TestVolumeControlDelegate* delegate = new TestVolumeControlDelegate(true); | 735 DummyVolumeControlDelegate* delegate = new DummyVolumeControlDelegate(true); |
| 689 ash::Shell::GetInstance()->system_tray_delegate()->SetVolumeControlDelegate( | 736 ash::Shell::GetInstance()->system_tray_delegate()->SetVolumeControlDelegate( |
| 690 scoped_ptr<VolumeControlDelegate>(delegate).Pass()); | 737 scoped_ptr<VolumeControlDelegate>(delegate).Pass()); |
| 691 EXPECT_EQ(0, delegate->handle_volume_mute_count()); | 738 EXPECT_EQ(0, delegate->handle_volume_mute_count()); |
| 692 EXPECT_TRUE(ProcessWithContext(volume_mute)); | 739 EXPECT_TRUE(ProcessWithContext(volume_mute)); |
| 693 EXPECT_EQ(1, delegate->handle_volume_mute_count()); | 740 EXPECT_EQ(1, delegate->handle_volume_mute_count()); |
| 694 EXPECT_EQ(volume_mute, delegate->last_accelerator()); | 741 EXPECT_EQ(volume_mute, delegate->last_accelerator()); |
| 695 EXPECT_EQ(0, delegate->handle_volume_down_count()); | 742 EXPECT_EQ(0, delegate->handle_volume_down_count()); |
| 696 EXPECT_TRUE(ProcessWithContext(volume_down)); | 743 EXPECT_TRUE(ProcessWithContext(volume_down)); |
| 697 EXPECT_EQ(1, delegate->handle_volume_down_count()); | 744 EXPECT_EQ(1, delegate->handle_volume_down_count()); |
| 698 EXPECT_EQ(volume_down, delegate->last_accelerator()); | 745 EXPECT_EQ(volume_down, delegate->last_accelerator()); |
| (...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1136 EXPECT_EQ(brightness_up, delegate->last_accelerator()); | 1183 EXPECT_EQ(brightness_up, delegate->last_accelerator()); |
| 1137 } | 1184 } |
| 1138 // Volume | 1185 // Volume |
| 1139 const ui::Accelerator volume_mute(ui::VKEY_VOLUME_MUTE, ui::EF_NONE); | 1186 const ui::Accelerator volume_mute(ui::VKEY_VOLUME_MUTE, ui::EF_NONE); |
| 1140 const ui::Accelerator volume_down(ui::VKEY_VOLUME_DOWN, ui::EF_NONE); | 1187 const ui::Accelerator volume_down(ui::VKEY_VOLUME_DOWN, ui::EF_NONE); |
| 1141 const ui::Accelerator volume_up(ui::VKEY_VOLUME_UP, ui::EF_NONE); | 1188 const ui::Accelerator volume_up(ui::VKEY_VOLUME_UP, ui::EF_NONE); |
| 1142 { | 1189 { |
| 1143 EXPECT_TRUE(ProcessWithContext(volume_mute)); | 1190 EXPECT_TRUE(ProcessWithContext(volume_mute)); |
| 1144 EXPECT_TRUE(ProcessWithContext(volume_down)); | 1191 EXPECT_TRUE(ProcessWithContext(volume_down)); |
| 1145 EXPECT_TRUE(ProcessWithContext(volume_up)); | 1192 EXPECT_TRUE(ProcessWithContext(volume_up)); |
| 1146 TestVolumeControlDelegate* delegate = | 1193 DummyVolumeControlDelegate* delegate = |
| 1147 new TestVolumeControlDelegate(false); | 1194 new DummyVolumeControlDelegate(false); |
| 1148 ash::Shell::GetInstance()->system_tray_delegate()->SetVolumeControlDelegate( | 1195 ash::Shell::GetInstance()->system_tray_delegate()->SetVolumeControlDelegate( |
| 1149 scoped_ptr<VolumeControlDelegate>(delegate).Pass()); | 1196 scoped_ptr<VolumeControlDelegate>(delegate).Pass()); |
| 1150 EXPECT_EQ(0, delegate->handle_volume_mute_count()); | 1197 EXPECT_EQ(0, delegate->handle_volume_mute_count()); |
| 1151 EXPECT_FALSE(ProcessWithContext(volume_mute)); | 1198 EXPECT_FALSE(ProcessWithContext(volume_mute)); |
| 1152 EXPECT_EQ(1, delegate->handle_volume_mute_count()); | 1199 EXPECT_EQ(1, delegate->handle_volume_mute_count()); |
| 1153 EXPECT_EQ(volume_mute, delegate->last_accelerator()); | 1200 EXPECT_EQ(volume_mute, delegate->last_accelerator()); |
| 1154 EXPECT_EQ(0, delegate->handle_volume_down_count()); | 1201 EXPECT_EQ(0, delegate->handle_volume_down_count()); |
| 1155 EXPECT_FALSE(ProcessWithContext(volume_down)); | 1202 EXPECT_FALSE(ProcessWithContext(volume_down)); |
| 1156 EXPECT_EQ(1, delegate->handle_volume_down_count()); | 1203 EXPECT_EQ(1, delegate->handle_volume_down_count()); |
| 1157 EXPECT_EQ(volume_down, delegate->last_accelerator()); | 1204 EXPECT_EQ(volume_down, delegate->last_accelerator()); |
| 1158 EXPECT_EQ(0, delegate->handle_volume_up_count()); | 1205 EXPECT_EQ(0, delegate->handle_volume_up_count()); |
| 1159 EXPECT_FALSE(ProcessWithContext(volume_up)); | 1206 EXPECT_FALSE(ProcessWithContext(volume_up)); |
| 1160 EXPECT_EQ(1, delegate->handle_volume_up_count()); | 1207 EXPECT_EQ(1, delegate->handle_volume_up_count()); |
| 1161 EXPECT_EQ(volume_up, delegate->last_accelerator()); | 1208 EXPECT_EQ(volume_up, delegate->last_accelerator()); |
| 1162 } | 1209 } |
| 1163 { | 1210 { |
| 1164 TestVolumeControlDelegate* delegate = new TestVolumeControlDelegate(true); | 1211 DummyVolumeControlDelegate* delegate = new DummyVolumeControlDelegate(true); |
| 1165 ash::Shell::GetInstance()->system_tray_delegate()->SetVolumeControlDelegate( | 1212 ash::Shell::GetInstance()->system_tray_delegate()->SetVolumeControlDelegate( |
| 1166 scoped_ptr<VolumeControlDelegate>(delegate).Pass()); | 1213 scoped_ptr<VolumeControlDelegate>(delegate).Pass()); |
| 1167 EXPECT_EQ(0, delegate->handle_volume_mute_count()); | 1214 EXPECT_EQ(0, delegate->handle_volume_mute_count()); |
| 1168 EXPECT_TRUE(ProcessWithContext(volume_mute)); | 1215 EXPECT_TRUE(ProcessWithContext(volume_mute)); |
| 1169 EXPECT_EQ(1, delegate->handle_volume_mute_count()); | 1216 EXPECT_EQ(1, delegate->handle_volume_mute_count()); |
| 1170 EXPECT_EQ(volume_mute, delegate->last_accelerator()); | 1217 EXPECT_EQ(volume_mute, delegate->last_accelerator()); |
| 1171 EXPECT_EQ(0, delegate->handle_volume_down_count()); | 1218 EXPECT_EQ(0, delegate->handle_volume_down_count()); |
| 1172 EXPECT_TRUE(ProcessWithContext(volume_down)); | 1219 EXPECT_TRUE(ProcessWithContext(volume_down)); |
| 1173 EXPECT_EQ(1, delegate->handle_volume_down_count()); | 1220 EXPECT_EQ(1, delegate->handle_volume_down_count()); |
| 1174 EXPECT_EQ(volume_down, delegate->last_accelerator()); | 1221 EXPECT_EQ(volume_down, delegate->last_accelerator()); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 1205 // Don't alert if we have a minimized window either. | 1252 // Don't alert if we have a minimized window either. |
| 1206 GetController()->PerformAction(WINDOW_MINIMIZE, dummy); | 1253 GetController()->PerformAction(WINDOW_MINIMIZE, dummy); |
| 1207 for (size_t i = 0; i < kActionsNeedingWindowLength; ++i) { | 1254 for (size_t i = 0; i < kActionsNeedingWindowLength; ++i) { |
| 1208 delegate->TriggerAccessibilityAlert(A11Y_ALERT_NONE); | 1255 delegate->TriggerAccessibilityAlert(A11Y_ALERT_NONE); |
| 1209 GetController()->PerformAction(kActionsNeedingWindow[i], dummy); | 1256 GetController()->PerformAction(kActionsNeedingWindow[i], dummy); |
| 1210 EXPECT_EQ(delegate->GetLastAccessibilityAlert(), A11Y_ALERT_NONE); | 1257 EXPECT_EQ(delegate->GetLastAccessibilityAlert(), A11Y_ALERT_NONE); |
| 1211 } | 1258 } |
| 1212 } | 1259 } |
| 1213 | 1260 |
| 1214 } // namespace ash | 1261 } // namespace ash |
| OLD | NEW |