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 | 6 |
7 #include "ash/accelerators/accelerator_table.h" | 7 #include "ash/accelerators/accelerator_table.h" |
8 #include "ash/aura/wm_window_aura.h" | 8 #include "ash/aura/wm_window_aura.h" |
9 #include "ash/common/accessibility_delegate.h" | 9 #include "ash/common/accessibility_delegate.h" |
10 #include "ash/common/accessibility_types.h" | 10 #include "ash/common/accessibility_types.h" |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 | 52 |
53 namespace ash { | 53 namespace ash { |
54 | 54 |
55 namespace { | 55 namespace { |
56 | 56 |
57 class TestTarget : public ui::AcceleratorTarget { | 57 class TestTarget : public ui::AcceleratorTarget { |
58 public: | 58 public: |
59 TestTarget() : accelerator_pressed_count_(0), accelerator_repeat_count_(0) {} | 59 TestTarget() : accelerator_pressed_count_(0), accelerator_repeat_count_(0) {} |
60 ~TestTarget() override {} | 60 ~TestTarget() override {} |
61 | 61 |
62 int accelerator_pressed_count() const { | 62 int accelerator_pressed_count() const { return accelerator_pressed_count_; } |
63 return accelerator_pressed_count_; | |
64 } | |
65 | 63 |
66 int accelerator_repeat_count() const { return accelerator_repeat_count_; } | 64 int accelerator_repeat_count() const { return accelerator_repeat_count_; } |
67 | 65 |
68 void reset() { | 66 void reset() { |
69 accelerator_pressed_count_ = 0; | 67 accelerator_pressed_count_ = 0; |
70 accelerator_repeat_count_ = 0; | 68 accelerator_repeat_count_ = 0; |
71 } | 69 } |
72 | 70 |
73 // Overridden from ui::AcceleratorTarget: | 71 // Overridden from ui::AcceleratorTarget: |
74 bool AcceleratorPressed(const ui::Accelerator& accelerator) override; | 72 bool AcceleratorPressed(const ui::Accelerator& accelerator) override; |
(...skipping 30 matching lines...) Expand all Loading... |
105 } | 103 } |
106 void SetBrightnessPercent(double percent, bool gradual) override {} | 104 void SetBrightnessPercent(double percent, bool gradual) override {} |
107 void GetBrightnessPercent( | 105 void GetBrightnessPercent( |
108 const base::Callback<void(double)>& callback) override { | 106 const base::Callback<void(double)>& callback) override { |
109 callback.Run(100.0); | 107 callback.Run(100.0); |
110 } | 108 } |
111 | 109 |
112 int handle_brightness_down_count() const { | 110 int handle_brightness_down_count() const { |
113 return handle_brightness_down_count_; | 111 return handle_brightness_down_count_; |
114 } | 112 } |
115 int handle_brightness_up_count() const { | 113 int handle_brightness_up_count() const { return handle_brightness_up_count_; } |
116 return handle_brightness_up_count_; | 114 const ui::Accelerator& last_accelerator() const { return last_accelerator_; } |
117 } | |
118 const ui::Accelerator& last_accelerator() const { | |
119 return last_accelerator_; | |
120 } | |
121 | 115 |
122 private: | 116 private: |
123 int handle_brightness_down_count_; | 117 int handle_brightness_down_count_; |
124 int handle_brightness_up_count_; | 118 int handle_brightness_up_count_; |
125 ui::Accelerator last_accelerator_; | 119 ui::Accelerator last_accelerator_; |
126 | 120 |
127 DISALLOW_COPY_AND_ASSIGN(DummyBrightnessControlDelegate); | 121 DISALLOW_COPY_AND_ASSIGN(DummyBrightnessControlDelegate); |
128 }; | 122 }; |
129 | 123 |
130 class DummyImeControlDelegate : public ImeControlDelegate { | 124 class DummyImeControlDelegate : public ImeControlDelegate { |
131 public: | 125 public: |
132 DummyImeControlDelegate() | 126 DummyImeControlDelegate() |
133 : handle_next_ime_count_(0), | 127 : handle_next_ime_count_(0), |
134 handle_previous_ime_count_(0), | 128 handle_previous_ime_count_(0), |
135 handle_switch_ime_count_(0) {} | 129 handle_switch_ime_count_(0) {} |
136 ~DummyImeControlDelegate() override {} | 130 ~DummyImeControlDelegate() override {} |
137 | 131 |
138 bool CanCycleIme() override { return true; } | 132 bool CanCycleIme() override { return true; } |
139 void HandleNextIme() override { ++handle_next_ime_count_; } | 133 void HandleNextIme() override { ++handle_next_ime_count_; } |
140 void HandlePreviousIme() override { | 134 void HandlePreviousIme() override { ++handle_previous_ime_count_; } |
141 ++handle_previous_ime_count_; | |
142 } | |
143 bool CanSwitchIme(const ui::Accelerator& accelerator) override { | 135 bool CanSwitchIme(const ui::Accelerator& accelerator) override { |
144 return true; | 136 return true; |
145 } | 137 } |
146 void HandleSwitchIme(const ui::Accelerator& accelerator) override { | 138 void HandleSwitchIme(const ui::Accelerator& accelerator) override { |
147 ++handle_switch_ime_count_; | 139 ++handle_switch_ime_count_; |
148 } | 140 } |
149 | 141 |
150 int handle_next_ime_count() const { | 142 int handle_next_ime_count() const { return handle_next_ime_count_; } |
151 return handle_next_ime_count_; | 143 int handle_previous_ime_count() const { return handle_previous_ime_count_; } |
152 } | 144 int handle_switch_ime_count() const { return handle_switch_ime_count_; } |
153 int handle_previous_ime_count() const { | |
154 return handle_previous_ime_count_; | |
155 } | |
156 int handle_switch_ime_count() const { | |
157 return handle_switch_ime_count_; | |
158 } | |
159 | 145 |
160 private: | 146 private: |
161 int handle_next_ime_count_; | 147 int handle_next_ime_count_; |
162 int handle_previous_ime_count_; | 148 int handle_previous_ime_count_; |
163 int handle_switch_ime_count_; | 149 int handle_switch_ime_count_; |
164 | 150 |
165 DISALLOW_COPY_AND_ASSIGN(DummyImeControlDelegate); | 151 DISALLOW_COPY_AND_ASSIGN(DummyImeControlDelegate); |
166 }; | 152 }; |
167 | 153 |
168 class DummyKeyboardBrightnessControlDelegate | 154 class DummyKeyboardBrightnessControlDelegate |
(...skipping 16 matching lines...) Expand all Loading... |
185 } | 171 } |
186 | 172 |
187 int handle_keyboard_brightness_down_count() const { | 173 int handle_keyboard_brightness_down_count() const { |
188 return handle_keyboard_brightness_down_count_; | 174 return handle_keyboard_brightness_down_count_; |
189 } | 175 } |
190 | 176 |
191 int handle_keyboard_brightness_up_count() const { | 177 int handle_keyboard_brightness_up_count() const { |
192 return handle_keyboard_brightness_up_count_; | 178 return handle_keyboard_brightness_up_count_; |
193 } | 179 } |
194 | 180 |
195 const ui::Accelerator& last_accelerator() const { | 181 const ui::Accelerator& last_accelerator() const { return last_accelerator_; } |
196 return last_accelerator_; | |
197 } | |
198 | 182 |
199 private: | 183 private: |
200 int handle_keyboard_brightness_down_count_; | 184 int handle_keyboard_brightness_down_count_; |
201 int handle_keyboard_brightness_up_count_; | 185 int handle_keyboard_brightness_up_count_; |
202 ui::Accelerator last_accelerator_; | 186 ui::Accelerator last_accelerator_; |
203 | 187 |
204 DISALLOW_COPY_AND_ASSIGN(DummyKeyboardBrightnessControlDelegate); | 188 DISALLOW_COPY_AND_ASSIGN(DummyKeyboardBrightnessControlDelegate); |
205 }; | 189 }; |
206 | 190 |
207 bool TestTarget::AcceleratorPressed(const ui::Accelerator& accelerator) { | 191 bool TestTarget::AcceleratorPressed(const ui::Accelerator& accelerator) { |
(...skipping 25 matching lines...) Expand all Loading... |
233 static bool ProcessInController(const ui::Accelerator& accelerator) { | 217 static bool ProcessInController(const ui::Accelerator& accelerator) { |
234 if (accelerator.type() == ui::ET_KEY_RELEASED) { | 218 if (accelerator.type() == ui::ET_KEY_RELEASED) { |
235 // If the |accelerator| should trigger on release, then we store the | 219 // If the |accelerator| should trigger on release, then we store the |
236 // pressed version of it first in history then the released one to | 220 // pressed version of it first in history then the released one to |
237 // simulate what happens in reality. | 221 // simulate what happens in reality. |
238 ui::Accelerator pressed_accelerator = accelerator; | 222 ui::Accelerator pressed_accelerator = accelerator; |
239 pressed_accelerator.set_type(ui::ET_KEY_PRESSED); | 223 pressed_accelerator.set_type(ui::ET_KEY_PRESSED); |
240 GetController()->accelerator_history()->StoreCurrentAccelerator( | 224 GetController()->accelerator_history()->StoreCurrentAccelerator( |
241 pressed_accelerator); | 225 pressed_accelerator); |
242 } | 226 } |
243 GetController()->accelerator_history()-> | 227 GetController()->accelerator_history()->StoreCurrentAccelerator( |
244 StoreCurrentAccelerator(accelerator); | 228 accelerator); |
245 return GetController()->Process(accelerator); | 229 return GetController()->Process(accelerator); |
246 } | 230 } |
247 | 231 |
248 static const ui::Accelerator& GetPreviousAccelerator() { | 232 static const ui::Accelerator& GetPreviousAccelerator() { |
249 return GetController()->accelerator_history()-> | 233 return GetController()->accelerator_history()->previous_accelerator(); |
250 previous_accelerator(); | |
251 } | 234 } |
252 | 235 |
253 static const ui::Accelerator& GetCurrentAccelerator() { | 236 static const ui::Accelerator& GetCurrentAccelerator() { |
254 return GetController()->accelerator_history()-> | 237 return GetController()->accelerator_history()->current_accelerator(); |
255 current_accelerator(); | |
256 } | 238 } |
257 | 239 |
258 // Several functions to access ExitWarningHandler (as friend). | 240 // Several functions to access ExitWarningHandler (as friend). |
259 static void StubForTest(ExitWarningHandler* ewh) { | 241 static void StubForTest(ExitWarningHandler* ewh) { |
260 ewh->stub_timer_for_test_ = true; | 242 ewh->stub_timer_for_test_ = true; |
261 } | 243 } |
262 static void Reset(ExitWarningHandler* ewh) { | 244 static void Reset(ExitWarningHandler* ewh) { |
263 ewh->state_ = ExitWarningHandler::IDLE; | 245 ewh->state_ = ExitWarningHandler::IDLE; |
264 } | 246 } |
265 static void SimulateTimerExpired(ExitWarningHandler* ewh) { | 247 static void SimulateTimerExpired(ExitWarningHandler* ewh) { |
266 ewh->TimerAction(); | 248 ewh->TimerAction(); |
267 } | 249 } |
268 static bool is_ui_shown(ExitWarningHandler* ewh) { | 250 static bool is_ui_shown(ExitWarningHandler* ewh) { return !!ewh->widget_; } |
269 return !!ewh->widget_; | |
270 } | |
271 static bool is_idle(ExitWarningHandler* ewh) { | 251 static bool is_idle(ExitWarningHandler* ewh) { |
272 return ewh->state_ == ExitWarningHandler::IDLE; | 252 return ewh->state_ == ExitWarningHandler::IDLE; |
273 } | 253 } |
274 static bool is_exiting(ExitWarningHandler* ewh) { | 254 static bool is_exiting(ExitWarningHandler* ewh) { |
275 return ewh->state_ == ExitWarningHandler::EXITING; | 255 return ewh->state_ == ExitWarningHandler::EXITING; |
276 } | 256 } |
277 aura::Window* CreatePanel() { | 257 aura::Window* CreatePanel() { |
278 aura::Window* window = | 258 aura::Window* window = CreateTestWindowInShellWithDelegateAndType( |
279 CreateTestWindowInShellWithDelegateAndType(NULL, | 259 NULL, ui::wm::WINDOW_TYPE_PANEL, 0, gfx::Rect(5, 5, 20, 20)); |
280 ui::wm::WINDOW_TYPE_PANEL, 0, gfx::Rect(5, 5, 20, 20)); | |
281 test::TestShelfDelegate* shelf_delegate = | 260 test::TestShelfDelegate* shelf_delegate = |
282 test::TestShelfDelegate::instance(); | 261 test::TestShelfDelegate::instance(); |
283 shelf_delegate->AddShelfItem(window); | 262 shelf_delegate->AddShelfItem(window); |
284 PanelLayoutManager* manager = | 263 PanelLayoutManager* manager = |
285 PanelLayoutManager::Get(WmWindowAura::Get(window)); | 264 PanelLayoutManager::Get(WmWindowAura::Get(window)); |
286 manager->Relayout(); | 265 manager->Relayout(); |
287 return window; | 266 return window; |
288 } | 267 } |
289 | 268 |
290 private: | 269 private: |
291 DISALLOW_COPY_AND_ASSIGN(AcceleratorControllerTest); | 270 DISALLOW_COPY_AND_ASSIGN(AcceleratorControllerTest); |
292 }; | 271 }; |
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
619 CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20))); | 598 CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20))); |
620 | 599 |
621 std::unique_ptr<aura::Window> window(CreatePanel()); | 600 std::unique_ptr<aura::Window> window(CreatePanel()); |
622 wm::WindowState* window_state = wm::GetWindowState(window.get()); | 601 wm::WindowState* window_state = wm::GetWindowState(window.get()); |
623 window_state->Activate(); | 602 window_state->Activate(); |
624 | 603 |
625 gfx::Rect window_restore_bounds2 = window->bounds(); | 604 gfx::Rect window_restore_bounds2 = window->bounds(); |
626 GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_DOCK_LEFT); | 605 GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_DOCK_LEFT); |
627 gfx::Rect expected_bounds = wm::GetDefaultLeftSnappedWindowBoundsInParent( | 606 gfx::Rect expected_bounds = wm::GetDefaultLeftSnappedWindowBoundsInParent( |
628 WmWindowAura::Get(window.get())); | 607 WmWindowAura::Get(window.get())); |
629 gfx::Rect window_restore_bounds = | 608 gfx::Rect window_restore_bounds = window_state->GetRestoreBoundsInScreen(); |
630 window_state->GetRestoreBoundsInScreen(); | |
631 EXPECT_NE(expected_bounds.ToString(), window->bounds().ToString()); | 609 EXPECT_NE(expected_bounds.ToString(), window->bounds().ToString()); |
632 EXPECT_FALSE(window_state->IsSnapped()); | 610 EXPECT_FALSE(window_state->IsSnapped()); |
633 EXPECT_FALSE(window_state->IsNormalOrSnapped()); | 611 EXPECT_FALSE(window_state->IsNormalOrSnapped()); |
634 EXPECT_TRUE(window_state->IsDocked()); | 612 EXPECT_TRUE(window_state->IsDocked()); |
635 window_state->Restore(); | 613 window_state->Restore(); |
636 GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_DOCK_RIGHT); | 614 GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_DOCK_RIGHT); |
637 EXPECT_TRUE(window_state->IsDocked()); | 615 EXPECT_TRUE(window_state->IsDocked()); |
638 GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_DOCK_RIGHT); | 616 GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_DOCK_RIGHT); |
639 EXPECT_FALSE(window_state->IsDocked()); | 617 EXPECT_FALSE(window_state->IsDocked()); |
640 EXPECT_EQ(window_restore_bounds.ToString(), | 618 EXPECT_EQ(window_restore_bounds.ToString(), |
641 window_restore_bounds2.ToString()); | 619 window_restore_bounds2.ToString()); |
642 EXPECT_EQ(window_restore_bounds.ToString(), window->bounds().ToString()); | 620 EXPECT_EQ(window_restore_bounds.ToString(), window->bounds().ToString()); |
643 } | 621 } |
644 | 622 |
645 TEST_F(AcceleratorControllerTest, CenterWindowAccelerator) { | 623 TEST_F(AcceleratorControllerTest, CenterWindowAccelerator) { |
646 std::unique_ptr<aura::Window> window( | 624 std::unique_ptr<aura::Window> window( |
647 CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20))); | 625 CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20))); |
648 wm::WindowState* window_state = wm::GetWindowState(window.get()); | 626 wm::WindowState* window_state = wm::GetWindowState(window.get()); |
649 window_state->Activate(); | 627 window_state->Activate(); |
650 | 628 |
651 // Center the window using accelerator. | 629 // Center the window using accelerator. |
652 GetController()->PerformActionIfEnabled(WINDOW_POSITION_CENTER); | 630 GetController()->PerformActionIfEnabled(WINDOW_POSITION_CENTER); |
653 gfx::Rect work_area = display::Screen::GetScreen() | 631 gfx::Rect work_area = display::Screen::GetScreen() |
654 ->GetDisplayNearestWindow(window.get()) | 632 ->GetDisplayNearestWindow(window.get()) |
655 .work_area(); | 633 .work_area(); |
656 gfx::Rect bounds = window->GetBoundsInScreen(); | 634 gfx::Rect bounds = window->GetBoundsInScreen(); |
657 EXPECT_NEAR(bounds.x() - work_area.x(), | 635 EXPECT_NEAR(bounds.x() - work_area.x(), work_area.right() - bounds.right(), |
658 work_area.right() - bounds.right(), | |
659 1); | 636 1); |
660 EXPECT_NEAR(bounds.y() - work_area.y(), | 637 EXPECT_NEAR(bounds.y() - work_area.y(), work_area.bottom() - bounds.bottom(), |
661 work_area.bottom() - bounds.bottom(), | |
662 1); | 638 1); |
663 | 639 |
664 // Add the window to docked container and try to center it. | 640 // Add the window to docked container and try to center it. |
665 window->SetBounds(gfx::Rect(0, 0, 20, 20)); | 641 window->SetBounds(gfx::Rect(0, 0, 20, 20)); |
666 const wm::WMEvent event(wm::WM_EVENT_DOCK); | 642 const wm::WMEvent event(wm::WM_EVENT_DOCK); |
667 wm::GetWindowState(window.get())->OnWMEvent(&event); | 643 wm::GetWindowState(window.get())->OnWMEvent(&event); |
668 EXPECT_EQ(kShellWindowId_DockedContainer, window->parent()->id()); | 644 EXPECT_EQ(kShellWindowId_DockedContainer, window->parent()->id()); |
669 | 645 |
670 gfx::Rect docked_bounds = window->GetBoundsInScreen(); | 646 gfx::Rect docked_bounds = window->GetBoundsInScreen(); |
671 GetController()->PerformActionIfEnabled(WINDOW_POSITION_CENTER); | 647 GetController()->PerformActionIfEnabled(WINDOW_POSITION_CENTER); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
716 EXPECT_EQ(0, target_b.accelerator_repeat_count()); | 692 EXPECT_EQ(0, target_b.accelerator_repeat_count()); |
717 EXPECT_EQ(4, target_a.accelerator_pressed_count()); | 693 EXPECT_EQ(4, target_a.accelerator_pressed_count()); |
718 EXPECT_EQ(4, target_a.accelerator_repeat_count()); | 694 EXPECT_EQ(4, target_a.accelerator_repeat_count()); |
719 } | 695 } |
720 | 696 |
721 TEST_F(AcceleratorControllerTest, Previous) { | 697 TEST_F(AcceleratorControllerTest, Previous) { |
722 ui::test::EventGenerator& generator = GetEventGenerator(); | 698 ui::test::EventGenerator& generator = GetEventGenerator(); |
723 generator.PressKey(ui::VKEY_VOLUME_MUTE, ui::EF_NONE); | 699 generator.PressKey(ui::VKEY_VOLUME_MUTE, ui::EF_NONE); |
724 generator.ReleaseKey(ui::VKEY_VOLUME_MUTE, ui::EF_NONE); | 700 generator.ReleaseKey(ui::VKEY_VOLUME_MUTE, ui::EF_NONE); |
725 | 701 |
726 EXPECT_EQ(ui::VKEY_VOLUME_MUTE, | 702 EXPECT_EQ(ui::VKEY_VOLUME_MUTE, GetPreviousAccelerator().key_code()); |
727 GetPreviousAccelerator().key_code()); | 703 EXPECT_EQ(ui::EF_NONE, GetPreviousAccelerator().modifiers()); |
728 EXPECT_EQ(ui::EF_NONE, | |
729 GetPreviousAccelerator().modifiers()); | |
730 | 704 |
731 generator.PressKey(ui::VKEY_TAB, ui::EF_CONTROL_DOWN); | 705 generator.PressKey(ui::VKEY_TAB, ui::EF_CONTROL_DOWN); |
732 generator.ReleaseKey(ui::VKEY_TAB, ui::EF_CONTROL_DOWN); | 706 generator.ReleaseKey(ui::VKEY_TAB, ui::EF_CONTROL_DOWN); |
733 | 707 |
734 EXPECT_EQ(ui::VKEY_TAB, | 708 EXPECT_EQ(ui::VKEY_TAB, GetPreviousAccelerator().key_code()); |
735 GetPreviousAccelerator().key_code()); | 709 EXPECT_EQ(ui::EF_CONTROL_DOWN, GetPreviousAccelerator().modifiers()); |
736 EXPECT_EQ(ui::EF_CONTROL_DOWN, | |
737 GetPreviousAccelerator().modifiers()); | |
738 } | 710 } |
739 | 711 |
740 TEST_F(AcceleratorControllerTest, DontRepeatToggleFullscreen) { | 712 TEST_F(AcceleratorControllerTest, DontRepeatToggleFullscreen) { |
741 const AcceleratorData accelerators[] = { | 713 const AcceleratorData accelerators[] = { |
742 {true, ui::VKEY_J, ui::EF_ALT_DOWN, TOGGLE_FULLSCREEN}, | 714 {true, ui::VKEY_J, ui::EF_ALT_DOWN, TOGGLE_FULLSCREEN}, |
743 {true, ui::VKEY_K, ui::EF_ALT_DOWN, TOGGLE_FULLSCREEN}, | 715 {true, ui::VKEY_K, ui::EF_ALT_DOWN, TOGGLE_FULLSCREEN}, |
744 }; | 716 }; |
745 GetController()->RegisterAccelerators(accelerators, arraysize(accelerators)); | 717 GetController()->RegisterAccelerators(accelerators, arraysize(accelerators)); |
746 | 718 |
747 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); | 719 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
783 // attempt to do here, so we disable it. | 755 // attempt to do here, so we disable it. |
784 DisableIME(); | 756 DisableIME(); |
785 ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); | 757 ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); |
786 TestTarget target; | 758 TestTarget target; |
787 GetController()->Register(accelerator_a, &target); | 759 GetController()->Register(accelerator_a, &target); |
788 | 760 |
789 // The accelerator is processed only once. | 761 // The accelerator is processed only once. |
790 ui::EventProcessor* dispatcher = | 762 ui::EventProcessor* dispatcher = |
791 Shell::GetPrimaryRootWindow()->GetHost()->event_processor(); | 763 Shell::GetPrimaryRootWindow()->GetHost()->event_processor(); |
792 #if defined(OS_WIN) | 764 #if defined(OS_WIN) |
793 MSG msg1 = { NULL, WM_KEYDOWN, ui::VKEY_A, 0 }; | 765 MSG msg1 = {NULL, WM_KEYDOWN, ui::VKEY_A, 0}; |
794 ui::KeyEvent key_event1(msg1); | 766 ui::KeyEvent key_event1(msg1); |
795 ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&key_event1); | 767 ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&key_event1); |
796 EXPECT_TRUE(key_event1.handled() || details.dispatcher_destroyed); | 768 EXPECT_TRUE(key_event1.handled() || details.dispatcher_destroyed); |
797 | 769 |
798 MSG msg2 = { NULL, WM_CHAR, L'A', 0 }; | 770 MSG msg2 = {NULL, WM_CHAR, L'A', 0}; |
799 ui::KeyEvent key_event2(msg2); | 771 ui::KeyEvent key_event2(msg2); |
800 details = dispatcher->OnEventFromSource(&key_event2); | 772 details = dispatcher->OnEventFromSource(&key_event2); |
801 EXPECT_FALSE(key_event2.handled() || details.dispatcher_destroyed); | 773 EXPECT_FALSE(key_event2.handled() || details.dispatcher_destroyed); |
802 | 774 |
803 MSG msg3 = { NULL, WM_KEYUP, ui::VKEY_A, 0 }; | 775 MSG msg3 = {NULL, WM_KEYUP, ui::VKEY_A, 0}; |
804 ui::KeyEvent key_event3(msg3); | 776 ui::KeyEvent key_event3(msg3); |
805 details = dispatcher->OnEventFromSource(&key_event3); | 777 details = dispatcher->OnEventFromSource(&key_event3); |
806 EXPECT_FALSE(key_event3.handled() || details.dispatcher_destroyed); | 778 EXPECT_FALSE(key_event3.handled() || details.dispatcher_destroyed); |
807 #elif defined(USE_X11) | 779 #elif defined(USE_X11) |
808 ui::ScopedXI2Event key_event; | 780 ui::ScopedXI2Event key_event; |
809 key_event.InitKeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_A, 0); | 781 key_event.InitKeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_A, 0); |
810 ui::KeyEvent key_event1(key_event); | 782 ui::KeyEvent key_event1(key_event); |
811 ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&key_event1); | 783 ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&key_event1); |
812 EXPECT_TRUE(key_event1.handled() || details.dispatcher_destroyed); | 784 EXPECT_TRUE(key_event1.handled() || details.dispatcher_destroyed); |
813 | 785 |
814 ui::KeyEvent key_event2('A', ui::VKEY_A, ui::EF_NONE); | 786 ui::KeyEvent key_event2('A', ui::VKEY_A, ui::EF_NONE); |
815 details = dispatcher->OnEventFromSource(&key_event2); | 787 details = dispatcher->OnEventFromSource(&key_event2); |
816 EXPECT_FALSE(key_event2.handled() || details.dispatcher_destroyed); | 788 EXPECT_FALSE(key_event2.handled() || details.dispatcher_destroyed); |
817 | 789 |
818 key_event.InitKeyEvent(ui::ET_KEY_RELEASED, ui::VKEY_A, 0); | 790 key_event.InitKeyEvent(ui::ET_KEY_RELEASED, ui::VKEY_A, 0); |
819 ui::KeyEvent key_event3(key_event); | 791 ui::KeyEvent key_event3(key_event); |
820 details = dispatcher->OnEventFromSource(&key_event3); | 792 details = dispatcher->OnEventFromSource(&key_event3); |
821 EXPECT_FALSE(key_event3.handled() || details.dispatcher_destroyed); | 793 EXPECT_FALSE(key_event3.handled() || details.dispatcher_destroyed); |
822 #endif | 794 #endif |
823 EXPECT_EQ(1, target.accelerator_pressed_count()); | 795 EXPECT_EQ(1, target.accelerator_pressed_count()); |
824 } | 796 } |
825 #endif | 797 #endif |
826 | 798 |
827 TEST_F(AcceleratorControllerTest, GlobalAccelerators) { | 799 TEST_F(AcceleratorControllerTest, GlobalAccelerators) { |
828 // CycleBackward | 800 // CycleBackward |
829 EXPECT_TRUE(ProcessInController( | 801 EXPECT_TRUE(ProcessInController( |
830 ui::Accelerator(ui::VKEY_TAB, ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN))); | 802 ui::Accelerator(ui::VKEY_TAB, ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN))); |
831 // CycleForward | 803 // CycleForward |
832 EXPECT_TRUE( | 804 EXPECT_TRUE( |
833 ProcessInController(ui::Accelerator( | 805 ProcessInController(ui::Accelerator(ui::VKEY_TAB, ui::EF_ALT_DOWN))); |
834 ui::VKEY_TAB, ui::EF_ALT_DOWN))); | |
835 // CycleLinear | 806 // CycleLinear |
836 EXPECT_TRUE(ProcessInController( | 807 EXPECT_TRUE(ProcessInController( |
837 ui::Accelerator(ui::VKEY_MEDIA_LAUNCH_APP1, ui::EF_NONE))); | 808 ui::Accelerator(ui::VKEY_MEDIA_LAUNCH_APP1, ui::EF_NONE))); |
838 | 809 |
839 #if defined(OS_CHROMEOS) | 810 #if defined(OS_CHROMEOS) |
840 // The "Take Screenshot", "Take Partial Screenshot", volume, brightness, and | 811 // The "Take Screenshot", "Take Partial Screenshot", volume, brightness, and |
841 // keyboard brightness accelerators are only defined on ChromeOS. | 812 // keyboard brightness accelerators are only defined on ChromeOS. |
842 { | 813 { |
843 test::TestScreenshotDelegate* delegate = GetScreenshotDelegate(); | 814 test::TestScreenshotDelegate* delegate = GetScreenshotDelegate(); |
844 delegate->set_can_take_screenshot(false); | 815 delegate->set_can_take_screenshot(false); |
845 EXPECT_TRUE(ProcessInController( | 816 EXPECT_TRUE(ProcessInController( |
846 ui::Accelerator(ui::VKEY_MEDIA_LAUNCH_APP1, ui::EF_CONTROL_DOWN))); | 817 ui::Accelerator(ui::VKEY_MEDIA_LAUNCH_APP1, ui::EF_CONTROL_DOWN))); |
847 EXPECT_TRUE( | 818 EXPECT_TRUE( |
848 ProcessInController(ui::Accelerator( | 819 ProcessInController(ui::Accelerator(ui::VKEY_PRINT, ui::EF_NONE))); |
849 ui::VKEY_PRINT, ui::EF_NONE))); | |
850 EXPECT_TRUE(ProcessInController(ui::Accelerator( | 820 EXPECT_TRUE(ProcessInController(ui::Accelerator( |
851 ui::VKEY_MEDIA_LAUNCH_APP1, ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN))); | 821 ui::VKEY_MEDIA_LAUNCH_APP1, ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN))); |
852 | 822 |
853 delegate->set_can_take_screenshot(true); | 823 delegate->set_can_take_screenshot(true); |
854 EXPECT_EQ(0, delegate->handle_take_screenshot_count()); | 824 EXPECT_EQ(0, delegate->handle_take_screenshot_count()); |
855 EXPECT_TRUE(ProcessInController( | 825 EXPECT_TRUE(ProcessInController( |
856 ui::Accelerator(ui::VKEY_MEDIA_LAUNCH_APP1, ui::EF_CONTROL_DOWN))); | 826 ui::Accelerator(ui::VKEY_MEDIA_LAUNCH_APP1, ui::EF_CONTROL_DOWN))); |
857 EXPECT_EQ(1, delegate->handle_take_screenshot_count()); | 827 EXPECT_EQ(1, delegate->handle_take_screenshot_count()); |
858 EXPECT_TRUE( | 828 EXPECT_TRUE( |
859 ProcessInController(ui::Accelerator( | 829 ProcessInController(ui::Accelerator(ui::VKEY_PRINT, ui::EF_NONE))); |
860 ui::VKEY_PRINT, ui::EF_NONE))); | |
861 EXPECT_EQ(2, delegate->handle_take_screenshot_count()); | 830 EXPECT_EQ(2, delegate->handle_take_screenshot_count()); |
862 EXPECT_TRUE(ProcessInController(ui::Accelerator( | 831 EXPECT_TRUE(ProcessInController(ui::Accelerator( |
863 ui::VKEY_MEDIA_LAUNCH_APP1, ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN))); | 832 ui::VKEY_MEDIA_LAUNCH_APP1, ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN))); |
864 EXPECT_EQ(2, delegate->handle_take_screenshot_count()); | 833 EXPECT_EQ(2, delegate->handle_take_screenshot_count()); |
865 } | 834 } |
866 const ui::Accelerator volume_mute(ui::VKEY_VOLUME_MUTE, ui::EF_NONE); | 835 const ui::Accelerator volume_mute(ui::VKEY_VOLUME_MUTE, ui::EF_NONE); |
867 const ui::Accelerator volume_down(ui::VKEY_VOLUME_DOWN, ui::EF_NONE); | 836 const ui::Accelerator volume_down(ui::VKEY_VOLUME_DOWN, ui::EF_NONE); |
868 const ui::Accelerator volume_up(ui::VKEY_VOLUME_UP, ui::EF_NONE); | 837 const ui::Accelerator volume_up(ui::VKEY_VOLUME_UP, ui::EF_NONE); |
869 { | 838 { |
870 TestVolumeControlDelegate* delegate = new TestVolumeControlDelegate; | 839 TestVolumeControlDelegate* delegate = new TestVolumeControlDelegate; |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
936 ui::Accelerator(ui::VKEY_Q, ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN))); | 905 ui::Accelerator(ui::VKEY_Q, ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN))); |
937 EXPECT_FALSE(is_idle(ewh)); | 906 EXPECT_FALSE(is_idle(ewh)); |
938 EXPECT_TRUE(is_ui_shown(ewh)); | 907 EXPECT_TRUE(is_ui_shown(ewh)); |
939 SimulateTimerExpired(ewh); | 908 SimulateTimerExpired(ewh); |
940 EXPECT_TRUE(is_idle(ewh)); | 909 EXPECT_TRUE(is_idle(ewh)); |
941 EXPECT_FALSE(is_ui_shown(ewh)); | 910 EXPECT_FALSE(is_ui_shown(ewh)); |
942 Reset(ewh); | 911 Reset(ewh); |
943 #endif | 912 #endif |
944 | 913 |
945 // New tab | 914 // New tab |
946 EXPECT_TRUE(ProcessInController( | 915 EXPECT_TRUE( |
947 ui::Accelerator(ui::VKEY_T, ui::EF_CONTROL_DOWN))); | 916 ProcessInController(ui::Accelerator(ui::VKEY_T, ui::EF_CONTROL_DOWN))); |
948 | 917 |
949 // New incognito window | 918 // New incognito window |
950 EXPECT_TRUE(ProcessInController( | 919 EXPECT_TRUE(ProcessInController( |
951 ui::Accelerator(ui::VKEY_N, ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN))); | 920 ui::Accelerator(ui::VKEY_N, ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN))); |
952 | 921 |
953 // New window | 922 // New window |
954 EXPECT_TRUE(ProcessInController( | 923 EXPECT_TRUE( |
955 ui::Accelerator(ui::VKEY_N, ui::EF_CONTROL_DOWN))); | 924 ProcessInController(ui::Accelerator(ui::VKEY_N, ui::EF_CONTROL_DOWN))); |
956 | 925 |
957 // Restore tab | 926 // Restore tab |
958 EXPECT_TRUE(ProcessInController( | 927 EXPECT_TRUE(ProcessInController( |
959 ui::Accelerator(ui::VKEY_T, ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN))); | 928 ui::Accelerator(ui::VKEY_T, ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN))); |
960 | 929 |
961 // Show task manager | 930 // Show task manager |
962 EXPECT_TRUE(ProcessInController( | 931 EXPECT_TRUE( |
963 ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_SHIFT_DOWN))); | 932 ProcessInController(ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_SHIFT_DOWN))); |
964 | 933 |
965 #if defined(OS_CHROMEOS) | 934 #if defined(OS_CHROMEOS) |
966 // Open file manager | 935 // Open file manager |
967 EXPECT_TRUE(ProcessInController( | 936 EXPECT_TRUE(ProcessInController( |
968 ui::Accelerator(ui::VKEY_M, ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN))); | 937 ui::Accelerator(ui::VKEY_M, ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN))); |
969 | 938 |
970 // Lock screen | 939 // Lock screen |
971 // NOTE: Accelerators that do not work on the lock screen need to be | 940 // NOTE: Accelerators that do not work on the lock screen need to be |
972 // tested before the sequence below is invoked because it causes a side | 941 // tested before the sequence below is invoked because it causes a side |
973 // effect of locking the screen. | 942 // effect of locking the screen. |
974 EXPECT_TRUE(ProcessInController( | 943 EXPECT_TRUE(ProcessInController( |
975 ui::Accelerator(ui::VKEY_L, ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN))); | 944 ui::Accelerator(ui::VKEY_L, ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN))); |
976 #endif | 945 #endif |
977 } | 946 } |
978 | 947 |
979 TEST_F(AcceleratorControllerTest, GlobalAcceleratorsToggleAppList) { | 948 TEST_F(AcceleratorControllerTest, GlobalAcceleratorsToggleAppList) { |
980 AccessibilityDelegate* delegate = | 949 AccessibilityDelegate* delegate = |
981 ash::Shell::GetInstance()->accessibility_delegate(); | 950 ash::Shell::GetInstance()->accessibility_delegate(); |
982 EXPECT_FALSE(ash::Shell::GetInstance()->GetAppListTargetVisibility()); | 951 EXPECT_FALSE(ash::Shell::GetInstance()->GetAppListTargetVisibility()); |
983 | 952 |
984 // The press event should not open the AppList, the release should instead. | 953 // The press event should not open the AppList, the release should instead. |
985 EXPECT_FALSE( | 954 EXPECT_FALSE( |
986 ProcessInController(ui::Accelerator(ui::VKEY_LWIN, ui::EF_NONE))); | 955 ProcessInController(ui::Accelerator(ui::VKEY_LWIN, ui::EF_NONE))); |
987 EXPECT_EQ(ui::VKEY_LWIN, | 956 EXPECT_EQ(ui::VKEY_LWIN, GetCurrentAccelerator().key_code()); |
988 GetCurrentAccelerator().key_code()); | |
989 | 957 |
990 EXPECT_FALSE(ash::Shell::GetInstance()->GetAppListTargetVisibility()); | 958 EXPECT_FALSE(ash::Shell::GetInstance()->GetAppListTargetVisibility()); |
991 | 959 |
992 EXPECT_TRUE( | 960 EXPECT_TRUE( |
993 ProcessInController(ReleaseAccelerator(ui::VKEY_LWIN, ui::EF_NONE))); | 961 ProcessInController(ReleaseAccelerator(ui::VKEY_LWIN, ui::EF_NONE))); |
994 EXPECT_TRUE(ash::Shell::GetInstance()->GetAppListTargetVisibility()); | 962 EXPECT_TRUE(ash::Shell::GetInstance()->GetAppListTargetVisibility()); |
995 | 963 |
996 EXPECT_EQ(ui::VKEY_LWIN, | 964 EXPECT_EQ(ui::VKEY_LWIN, GetPreviousAccelerator().key_code()); |
997 GetPreviousAccelerator().key_code()); | |
998 | 965 |
999 // When spoken feedback is on, the AppList should not toggle. | 966 // When spoken feedback is on, the AppList should not toggle. |
1000 delegate->ToggleSpokenFeedback(A11Y_NOTIFICATION_NONE); | 967 delegate->ToggleSpokenFeedback(A11Y_NOTIFICATION_NONE); |
1001 EXPECT_FALSE( | 968 EXPECT_FALSE( |
1002 ProcessInController(ui::Accelerator(ui::VKEY_LWIN, ui::EF_NONE))); | 969 ProcessInController(ui::Accelerator(ui::VKEY_LWIN, ui::EF_NONE))); |
1003 EXPECT_FALSE( | 970 EXPECT_FALSE( |
1004 ProcessInController(ReleaseAccelerator( | 971 ProcessInController(ReleaseAccelerator(ui::VKEY_LWIN, ui::EF_NONE))); |
1005 ui::VKEY_LWIN, ui::EF_NONE))); | |
1006 delegate->ToggleSpokenFeedback(A11Y_NOTIFICATION_NONE); | 972 delegate->ToggleSpokenFeedback(A11Y_NOTIFICATION_NONE); |
1007 EXPECT_TRUE(ash::Shell::GetInstance()->GetAppListTargetVisibility()); | 973 EXPECT_TRUE(ash::Shell::GetInstance()->GetAppListTargetVisibility()); |
1008 | 974 |
1009 EXPECT_FALSE( | 975 EXPECT_FALSE( |
1010 ProcessInController(ui::Accelerator(ui::VKEY_LWIN, ui::EF_NONE))); | 976 ProcessInController(ui::Accelerator(ui::VKEY_LWIN, ui::EF_NONE))); |
1011 EXPECT_TRUE( | 977 EXPECT_TRUE( |
1012 ProcessInController(ReleaseAccelerator( | 978 ProcessInController(ReleaseAccelerator(ui::VKEY_LWIN, ui::EF_NONE))); |
1013 ui::VKEY_LWIN, ui::EF_NONE))); | |
1014 EXPECT_FALSE(ash::Shell::GetInstance()->GetAppListTargetVisibility()); | 979 EXPECT_FALSE(ash::Shell::GetInstance()->GetAppListTargetVisibility()); |
1015 | 980 |
1016 // When spoken feedback is on, the AppList should not toggle. | 981 // When spoken feedback is on, the AppList should not toggle. |
1017 delegate->ToggleSpokenFeedback(A11Y_NOTIFICATION_NONE); | 982 delegate->ToggleSpokenFeedback(A11Y_NOTIFICATION_NONE); |
1018 EXPECT_FALSE( | 983 EXPECT_FALSE( |
1019 ProcessInController(ui::Accelerator(ui::VKEY_LWIN, ui::EF_NONE))); | 984 ProcessInController(ui::Accelerator(ui::VKEY_LWIN, ui::EF_NONE))); |
1020 EXPECT_FALSE( | 985 EXPECT_FALSE( |
1021 ProcessInController(ReleaseAccelerator( | 986 ProcessInController(ReleaseAccelerator(ui::VKEY_LWIN, ui::EF_NONE))); |
1022 ui::VKEY_LWIN, ui::EF_NONE))); | |
1023 delegate->ToggleSpokenFeedback(A11Y_NOTIFICATION_NONE); | 987 delegate->ToggleSpokenFeedback(A11Y_NOTIFICATION_NONE); |
1024 EXPECT_FALSE(ash::Shell::GetInstance()->GetAppListTargetVisibility()); | 988 EXPECT_FALSE(ash::Shell::GetInstance()->GetAppListTargetVisibility()); |
1025 | 989 |
1026 #if defined(OS_CHROMEOS) | 990 #if defined(OS_CHROMEOS) |
1027 // The press of VKEY_BROWSER_SEARCH should toggle the AppList | 991 // The press of VKEY_BROWSER_SEARCH should toggle the AppList |
1028 EXPECT_TRUE(ProcessInController(ui::Accelerator(ui::VKEY_BROWSER_SEARCH, | 992 EXPECT_TRUE(ProcessInController( |
1029 ui::EF_NONE))); | 993 ui::Accelerator(ui::VKEY_BROWSER_SEARCH, ui::EF_NONE))); |
1030 EXPECT_TRUE(ash::Shell::GetInstance()->GetAppListTargetVisibility()); | 994 EXPECT_TRUE(ash::Shell::GetInstance()->GetAppListTargetVisibility()); |
1031 EXPECT_FALSE(ProcessInController(ReleaseAccelerator(ui::VKEY_BROWSER_SEARCH, | 995 EXPECT_FALSE(ProcessInController( |
1032 ui::EF_NONE))); | 996 ReleaseAccelerator(ui::VKEY_BROWSER_SEARCH, ui::EF_NONE))); |
1033 EXPECT_TRUE(ash::Shell::GetInstance()->GetAppListTargetVisibility()); | 997 EXPECT_TRUE(ash::Shell::GetInstance()->GetAppListTargetVisibility()); |
1034 #endif | 998 #endif |
1035 } | 999 } |
1036 | 1000 |
1037 TEST_F(AcceleratorControllerTest, ImeGlobalAccelerators) { | 1001 TEST_F(AcceleratorControllerTest, ImeGlobalAccelerators) { |
1038 // Test IME shortcuts. | 1002 // Test IME shortcuts. |
1039 ui::Accelerator control_space_down(ui::VKEY_SPACE, ui::EF_CONTROL_DOWN); | 1003 ui::Accelerator control_space_down(ui::VKEY_SPACE, ui::EF_CONTROL_DOWN); |
1040 control_space_down.set_type(ui::ET_KEY_PRESSED); | 1004 control_space_down.set_type(ui::ET_KEY_PRESSED); |
1041 ui::Accelerator control_space_up(ui::VKEY_SPACE, ui::EF_CONTROL_DOWN); | 1005 ui::Accelerator control_space_up(ui::VKEY_SPACE, ui::EF_CONTROL_DOWN); |
1042 control_space_up.set_type(ui::ET_KEY_RELEASED); | 1006 control_space_up.set_type(ui::ET_KEY_RELEASED); |
(...skipping 28 matching lines...) Expand all Loading... |
1071 EXPECT_EQ(4, delegate->handle_switch_ime_count()); | 1035 EXPECT_EQ(4, delegate->handle_switch_ime_count()); |
1072 EXPECT_TRUE(ProcessInController(hangul)); | 1036 EXPECT_TRUE(ProcessInController(hangul)); |
1073 EXPECT_EQ(5, delegate->handle_switch_ime_count()); | 1037 EXPECT_EQ(5, delegate->handle_switch_ime_count()); |
1074 } | 1038 } |
1075 | 1039 |
1076 // TODO(nona|mazda): Remove this when crbug.com/139556 in a better way. | 1040 // TODO(nona|mazda): Remove this when crbug.com/139556 in a better way. |
1077 TEST_F(AcceleratorControllerTest, ImeGlobalAcceleratorsWorkaround139556) { | 1041 TEST_F(AcceleratorControllerTest, ImeGlobalAcceleratorsWorkaround139556) { |
1078 // The workaround for crbug.com/139556 depends on the fact that we don't | 1042 // The workaround for crbug.com/139556 depends on the fact that we don't |
1079 // use Shift+Alt+Enter/Space with ET_KEY_PRESSED as an accelerator. Test it. | 1043 // use Shift+Alt+Enter/Space with ET_KEY_PRESSED as an accelerator. Test it. |
1080 const ui::Accelerator shift_alt_return_press( | 1044 const ui::Accelerator shift_alt_return_press( |
1081 ui::VKEY_RETURN, | 1045 ui::VKEY_RETURN, ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN); |
1082 ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN); | |
1083 EXPECT_FALSE(ProcessInController(shift_alt_return_press)); | 1046 EXPECT_FALSE(ProcessInController(shift_alt_return_press)); |
1084 const ui::Accelerator shift_alt_space_press( | 1047 const ui::Accelerator shift_alt_space_press( |
1085 ui::VKEY_SPACE, | 1048 ui::VKEY_SPACE, ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN); |
1086 ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN); | |
1087 EXPECT_FALSE(ProcessInController(shift_alt_space_press)); | 1049 EXPECT_FALSE(ProcessInController(shift_alt_space_press)); |
1088 } | 1050 } |
1089 | 1051 |
1090 TEST_F(AcceleratorControllerTest, PreferredReservedAccelerators) { | 1052 TEST_F(AcceleratorControllerTest, PreferredReservedAccelerators) { |
1091 #if defined(OS_CHROMEOS) | 1053 #if defined(OS_CHROMEOS) |
1092 // Power key is reserved on chromeos. | 1054 // Power key is reserved on chromeos. |
1093 EXPECT_TRUE(GetController()->IsReserved( | 1055 EXPECT_TRUE(GetController()->IsReserved( |
1094 ui::Accelerator(ui::VKEY_POWER, ui::EF_NONE))); | 1056 ui::Accelerator(ui::VKEY_POWER, ui::EF_NONE))); |
1095 EXPECT_FALSE(GetController()->IsPreferred( | 1057 EXPECT_FALSE(GetController()->IsPreferred( |
1096 ui::Accelerator(ui::VKEY_POWER, ui::EF_NONE))); | 1058 ui::Accelerator(ui::VKEY_POWER, ui::EF_NONE))); |
1097 #endif | 1059 #endif |
1098 // ALT+Tab are not reserved but preferred. | 1060 // ALT+Tab are not reserved but preferred. |
1099 EXPECT_FALSE(GetController()->IsReserved( | 1061 EXPECT_FALSE(GetController()->IsReserved( |
1100 ui::Accelerator(ui::VKEY_TAB, ui::EF_ALT_DOWN))); | 1062 ui::Accelerator(ui::VKEY_TAB, ui::EF_ALT_DOWN))); |
1101 EXPECT_FALSE(GetController()->IsReserved( | 1063 EXPECT_FALSE(GetController()->IsReserved( |
1102 ui::Accelerator(ui::VKEY_TAB, ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN))); | 1064 ui::Accelerator(ui::VKEY_TAB, ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN))); |
1103 EXPECT_TRUE(GetController()->IsPreferred( | 1065 EXPECT_TRUE(GetController()->IsPreferred( |
1104 ui::Accelerator(ui::VKEY_TAB, ui::EF_ALT_DOWN))); | 1066 ui::Accelerator(ui::VKEY_TAB, ui::EF_ALT_DOWN))); |
1105 EXPECT_TRUE(GetController()->IsPreferred( | 1067 EXPECT_TRUE(GetController()->IsPreferred( |
1106 ui::Accelerator(ui::VKEY_TAB, ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN))); | 1068 ui::Accelerator(ui::VKEY_TAB, ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN))); |
1107 | 1069 |
1108 // Others are not reserved nor preferred | 1070 // Others are not reserved nor preferred |
1109 EXPECT_FALSE(GetController()->IsReserved( | 1071 EXPECT_FALSE(GetController()->IsReserved( |
1110 ui::Accelerator(ui::VKEY_PRINT, ui::EF_NONE))); | 1072 ui::Accelerator(ui::VKEY_PRINT, ui::EF_NONE))); |
1111 EXPECT_FALSE(GetController()->IsPreferred( | 1073 EXPECT_FALSE(GetController()->IsPreferred( |
1112 ui::Accelerator(ui::VKEY_PRINT, ui::EF_NONE))); | 1074 ui::Accelerator(ui::VKEY_PRINT, ui::EF_NONE))); |
1113 EXPECT_FALSE(GetController()->IsReserved( | 1075 EXPECT_FALSE( |
1114 ui::Accelerator(ui::VKEY_TAB, ui::EF_NONE))); | 1076 GetController()->IsReserved(ui::Accelerator(ui::VKEY_TAB, ui::EF_NONE))); |
1115 EXPECT_FALSE(GetController()->IsPreferred( | 1077 EXPECT_FALSE( |
1116 ui::Accelerator(ui::VKEY_TAB, ui::EF_NONE))); | 1078 GetController()->IsPreferred(ui::Accelerator(ui::VKEY_TAB, ui::EF_NONE))); |
1117 EXPECT_FALSE(GetController()->IsReserved( | 1079 EXPECT_FALSE( |
1118 ui::Accelerator(ui::VKEY_A, ui::EF_NONE))); | 1080 GetController()->IsReserved(ui::Accelerator(ui::VKEY_A, ui::EF_NONE))); |
1119 EXPECT_FALSE(GetController()->IsPreferred( | 1081 EXPECT_FALSE( |
1120 ui::Accelerator(ui::VKEY_A, ui::EF_NONE))); | 1082 GetController()->IsPreferred(ui::Accelerator(ui::VKEY_A, ui::EF_NONE))); |
1121 } | 1083 } |
1122 | 1084 |
1123 namespace { | 1085 namespace { |
1124 | 1086 |
1125 class PreferredReservedAcceleratorsTest : public test::AshTestBase { | 1087 class PreferredReservedAcceleratorsTest : public test::AshTestBase { |
1126 public: | 1088 public: |
1127 PreferredReservedAcceleratorsTest() {} | 1089 PreferredReservedAcceleratorsTest() {} |
1128 ~PreferredReservedAcceleratorsTest() override {} | 1090 ~PreferredReservedAcceleratorsTest() override {} |
1129 | 1091 |
1130 // test::AshTestBase: | 1092 // test::AshTestBase: |
1131 void SetUp() override { | 1093 void SetUp() override { |
1132 AshTestBase::SetUp(); | 1094 AshTestBase::SetUp(); |
1133 Shell::GetInstance()->lock_state_controller()-> | 1095 Shell::GetInstance()->lock_state_controller()->set_animator_for_test( |
1134 set_animator_for_test(new test::TestSessionStateAnimator); | 1096 new test::TestSessionStateAnimator); |
1135 } | 1097 } |
1136 | 1098 |
1137 private: | 1099 private: |
1138 DISALLOW_COPY_AND_ASSIGN(PreferredReservedAcceleratorsTest); | 1100 DISALLOW_COPY_AND_ASSIGN(PreferredReservedAcceleratorsTest); |
1139 }; | 1101 }; |
1140 | 1102 |
1141 } // namespace | 1103 } // namespace |
1142 | 1104 |
1143 TEST_F(PreferredReservedAcceleratorsTest, AcceleratorsWithFullscreen) { | 1105 TEST_F(PreferredReservedAcceleratorsTest, AcceleratorsWithFullscreen) { |
1144 aura::Window* w1 = CreateTestWindowInShellWithId(0); | 1106 aura::Window* w1 = CreateTestWindowInShellWithId(0); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1208 ASSERT_EQ(w1, wm::GetActiveWindow()); | 1170 ASSERT_EQ(w1, wm::GetActiveWindow()); |
1209 generator.PressKey(ui::VKEY_TAB, ui::EF_ALT_DOWN); | 1171 generator.PressKey(ui::VKEY_TAB, ui::EF_ALT_DOWN); |
1210 generator.ReleaseKey(ui::VKEY_TAB, ui::EF_ALT_DOWN); | 1172 generator.ReleaseKey(ui::VKEY_TAB, ui::EF_ALT_DOWN); |
1211 ASSERT_EQ(w1, wm::GetActiveWindow()); | 1173 ASSERT_EQ(w1, wm::GetActiveWindow()); |
1212 ASSERT_NE(w2, wm::GetActiveWindow()); | 1174 ASSERT_NE(w2, wm::GetActiveWindow()); |
1213 } | 1175 } |
1214 | 1176 |
1215 #if defined(OS_CHROMEOS) | 1177 #if defined(OS_CHROMEOS) |
1216 TEST_F(AcceleratorControllerTest, DisallowedAtModalWindow) { | 1178 TEST_F(AcceleratorControllerTest, DisallowedAtModalWindow) { |
1217 std::set<AcceleratorAction> all_actions; | 1179 std::set<AcceleratorAction> all_actions; |
1218 for (size_t i = 0 ; i < kAcceleratorDataLength; ++i) | 1180 for (size_t i = 0; i < kAcceleratorDataLength; ++i) |
1219 all_actions.insert(kAcceleratorData[i].action); | 1181 all_actions.insert(kAcceleratorData[i].action); |
1220 std::set<AcceleratorAction> all_debug_actions; | 1182 std::set<AcceleratorAction> all_debug_actions; |
1221 for (size_t i = 0 ; i < kDebugAcceleratorDataLength; ++i) | 1183 for (size_t i = 0; i < kDebugAcceleratorDataLength; ++i) |
1222 all_debug_actions.insert(kDebugAcceleratorData[i].action); | 1184 all_debug_actions.insert(kDebugAcceleratorData[i].action); |
1223 | 1185 |
1224 std::set<AcceleratorAction> actionsAllowedAtModalWindow; | 1186 std::set<AcceleratorAction> actionsAllowedAtModalWindow; |
1225 for (size_t k = 0 ; k < kActionsAllowedAtModalWindowLength; ++k) | 1187 for (size_t k = 0; k < kActionsAllowedAtModalWindowLength; ++k) |
1226 actionsAllowedAtModalWindow.insert(kActionsAllowedAtModalWindow[k]); | 1188 actionsAllowedAtModalWindow.insert(kActionsAllowedAtModalWindow[k]); |
1227 for (std::set<AcceleratorAction>::const_iterator it = | 1189 for (std::set<AcceleratorAction>::const_iterator it = |
1228 actionsAllowedAtModalWindow.begin(); | 1190 actionsAllowedAtModalWindow.begin(); |
1229 it != actionsAllowedAtModalWindow.end(); ++it) { | 1191 it != actionsAllowedAtModalWindow.end(); ++it) { |
1230 EXPECT_TRUE(all_actions.find(*it) != all_actions.end() || | 1192 EXPECT_TRUE(all_actions.find(*it) != all_actions.end() || |
1231 all_debug_actions.find(*it) != all_debug_actions.end()) | 1193 all_debug_actions.find(*it) != all_debug_actions.end()) |
1232 << " action from kActionsAllowedAtModalWindow" | 1194 << " action from kActionsAllowedAtModalWindow" |
1233 << " not found in kAcceleratorData or kDebugAcceleratorData. " | 1195 << " not found in kAcceleratorData or kDebugAcceleratorData. " |
1234 << "action: " << *it; | 1196 << "action: " << *it; |
1235 } | 1197 } |
(...skipping 12 matching lines...) Expand all Loading... |
1248 // Testing of top row (F5-F10) accelerators that should still work | 1210 // Testing of top row (F5-F10) accelerators that should still work |
1249 // when a modal window is open | 1211 // when a modal window is open |
1250 // | 1212 // |
1251 // Screenshot | 1213 // Screenshot |
1252 { | 1214 { |
1253 test::TestScreenshotDelegate* delegate = GetScreenshotDelegate(); | 1215 test::TestScreenshotDelegate* delegate = GetScreenshotDelegate(); |
1254 delegate->set_can_take_screenshot(false); | 1216 delegate->set_can_take_screenshot(false); |
1255 EXPECT_TRUE(ProcessInController( | 1217 EXPECT_TRUE(ProcessInController( |
1256 ui::Accelerator(ui::VKEY_MEDIA_LAUNCH_APP1, ui::EF_CONTROL_DOWN))); | 1218 ui::Accelerator(ui::VKEY_MEDIA_LAUNCH_APP1, ui::EF_CONTROL_DOWN))); |
1257 EXPECT_TRUE( | 1219 EXPECT_TRUE( |
1258 ProcessInController(ui::Accelerator( | 1220 ProcessInController(ui::Accelerator(ui::VKEY_PRINT, ui::EF_NONE))); |
1259 ui::VKEY_PRINT, ui::EF_NONE))); | |
1260 EXPECT_TRUE(ProcessInController(ui::Accelerator( | 1221 EXPECT_TRUE(ProcessInController(ui::Accelerator( |
1261 ui::VKEY_MEDIA_LAUNCH_APP1, ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN))); | 1222 ui::VKEY_MEDIA_LAUNCH_APP1, ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN))); |
1262 delegate->set_can_take_screenshot(true); | 1223 delegate->set_can_take_screenshot(true); |
1263 EXPECT_EQ(0, delegate->handle_take_screenshot_count()); | 1224 EXPECT_EQ(0, delegate->handle_take_screenshot_count()); |
1264 EXPECT_TRUE(ProcessInController( | 1225 EXPECT_TRUE(ProcessInController( |
1265 ui::Accelerator(ui::VKEY_MEDIA_LAUNCH_APP1, ui::EF_CONTROL_DOWN))); | 1226 ui::Accelerator(ui::VKEY_MEDIA_LAUNCH_APP1, ui::EF_CONTROL_DOWN))); |
1266 EXPECT_EQ(1, delegate->handle_take_screenshot_count()); | 1227 EXPECT_EQ(1, delegate->handle_take_screenshot_count()); |
1267 EXPECT_TRUE( | 1228 EXPECT_TRUE( |
1268 ProcessInController(ui::Accelerator( | 1229 ProcessInController(ui::Accelerator(ui::VKEY_PRINT, ui::EF_NONE))); |
1269 ui::VKEY_PRINT, ui::EF_NONE))); | |
1270 EXPECT_EQ(2, delegate->handle_take_screenshot_count()); | 1230 EXPECT_EQ(2, delegate->handle_take_screenshot_count()); |
1271 EXPECT_TRUE(ProcessInController(ui::Accelerator( | 1231 EXPECT_TRUE(ProcessInController(ui::Accelerator( |
1272 ui::VKEY_MEDIA_LAUNCH_APP1, ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN))); | 1232 ui::VKEY_MEDIA_LAUNCH_APP1, ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN))); |
1273 EXPECT_EQ(2, delegate->handle_take_screenshot_count()); | 1233 EXPECT_EQ(2, delegate->handle_take_screenshot_count()); |
1274 } | 1234 } |
1275 // Brightness | 1235 // Brightness |
1276 const ui::Accelerator brightness_down(ui::VKEY_BRIGHTNESS_DOWN, ui::EF_NONE); | 1236 const ui::Accelerator brightness_down(ui::VKEY_BRIGHTNESS_DOWN, ui::EF_NONE); |
1277 const ui::Accelerator brightness_up(ui::VKEY_BRIGHTNESS_UP, ui::EF_NONE); | 1237 const ui::Accelerator brightness_up(ui::VKEY_BRIGHTNESS_UP, ui::EF_NONE); |
1278 { | 1238 { |
1279 DummyBrightnessControlDelegate* delegate = | 1239 DummyBrightnessControlDelegate* delegate = |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1447 EXPECT_TRUE(IsMessageCenterEmpty()); | 1407 EXPECT_TRUE(IsMessageCenterEmpty()); |
1448 | 1408 |
1449 // If the action is LOCK_SCREEN, we must reset the state by unlocking the | 1409 // If the action is LOCK_SCREEN, we must reset the state by unlocking the |
1450 // screen before we proceed testing the rest of accelerators. | 1410 // screen before we proceed testing the rest of accelerators. |
1451 ResetStateIfNeeded(); | 1411 ResetStateIfNeeded(); |
1452 } | 1412 } |
1453 } | 1413 } |
1454 #endif // defined(OS_CHROMEOS) | 1414 #endif // defined(OS_CHROMEOS) |
1455 | 1415 |
1456 } // namespace ash | 1416 } // namespace ash |
OLD | NEW |