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/ime_control_delegate.h" | 8 #include "ash/ime_control_delegate.h" |
9 #include "ash/screenshot_delegate.h" | 9 #include "ash/screenshot_delegate.h" |
10 #include "ash/shell.h" | 10 #include "ash/shell.h" |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 int handle_take_screenshot_count() const { | 86 int handle_take_screenshot_count() const { |
87 return handle_take_screenshot_count_; | 87 return handle_take_screenshot_count_; |
88 } | 88 } |
89 | 89 |
90 private: | 90 private: |
91 int handle_take_screenshot_count_; | 91 int handle_take_screenshot_count_; |
92 | 92 |
93 DISALLOW_COPY_AND_ASSIGN(DummyScreenshotDelegate); | 93 DISALLOW_COPY_AND_ASSIGN(DummyScreenshotDelegate); |
94 }; | 94 }; |
95 | 95 |
96 class DummyCapsLockDelegate : public CapsLockDelegate { | |
97 public: | |
98 explicit DummyCapsLockDelegate(bool consume) | |
99 : consume_(consume), | |
100 handle_caps_lock_count_(0) { | |
101 } | |
102 virtual ~DummyCapsLockDelegate() {} | |
103 | |
104 virtual bool HandleToggleCapsLock() OVERRIDE { | |
105 ++handle_caps_lock_count_; | |
106 return consume_; | |
107 } | |
108 | |
109 int handle_caps_lock_count() const { | |
110 return handle_caps_lock_count_; | |
111 } | |
112 | |
113 private: | |
114 const bool consume_; | |
115 int handle_caps_lock_count_; | |
116 | |
117 DISALLOW_COPY_AND_ASSIGN(DummyCapsLockDelegate); | |
118 }; | |
119 | |
120 class DummyVolumeControlDelegate : public VolumeControlDelegate { | 96 class DummyVolumeControlDelegate : public VolumeControlDelegate { |
121 public: | 97 public: |
122 explicit DummyVolumeControlDelegate(bool consume) | 98 explicit DummyVolumeControlDelegate(bool consume) |
123 : consume_(consume), | 99 : consume_(consume), |
124 handle_volume_mute_count_(0), | 100 handle_volume_mute_count_(0), |
125 handle_volume_down_count_(0), | 101 handle_volume_down_count_(0), |
126 handle_volume_up_count_(0) { | 102 handle_volume_up_count_(0) { |
127 } | 103 } |
128 virtual ~DummyVolumeControlDelegate() {} | 104 virtual ~DummyVolumeControlDelegate() {} |
129 | 105 |
(...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
595 ShellDelegate* delegate = ash::Shell::GetInstance()->delegate(); | 571 ShellDelegate* delegate = ash::Shell::GetInstance()->delegate(); |
596 delegate->ToggleSpokenFeedback(); | 572 delegate->ToggleSpokenFeedback(); |
597 EXPECT_FALSE(GetController()->Process( | 573 EXPECT_FALSE(GetController()->Process( |
598 ui::Accelerator(ui::VKEY_LWIN, ui::EF_NONE))); | 574 ui::Accelerator(ui::VKEY_LWIN, ui::EF_NONE))); |
599 delegate->ToggleSpokenFeedback(); | 575 delegate->ToggleSpokenFeedback(); |
600 EXPECT_TRUE(GetController()->Process( | 576 EXPECT_TRUE(GetController()->Process( |
601 ui::Accelerator(ui::VKEY_LWIN, ui::EF_NONE))); | 577 ui::Accelerator(ui::VKEY_LWIN, ui::EF_NONE))); |
602 } | 578 } |
603 // DisableCapsLock | 579 // DisableCapsLock |
604 { | 580 { |
| 581 CapsLockDelegate* delegate = Shell::GetInstance()->caps_lock_delegate(); |
| 582 delegate->SetCapsLockEnabled(true); |
| 583 EXPECT_TRUE(delegate->IsCapsLockEnabled()); |
605 // Handled only on key release. | 584 // Handled only on key release. |
606 EXPECT_FALSE(GetController()->Process( | 585 EXPECT_FALSE(GetController()->Process( |
607 ui::Accelerator(ui::VKEY_LSHIFT, ui::EF_NONE))); | 586 ui::Accelerator(ui::VKEY_LSHIFT, ui::EF_NONE))); |
| 587 EXPECT_TRUE(delegate->IsCapsLockEnabled()); |
608 EXPECT_TRUE(GetController()->Process( | 588 EXPECT_TRUE(GetController()->Process( |
609 ReleaseAccelerator(ui::VKEY_SHIFT, ui::EF_NONE))); | 589 ReleaseAccelerator(ui::VKEY_SHIFT, ui::EF_NONE))); |
| 590 EXPECT_FALSE(delegate->IsCapsLockEnabled()); |
| 591 delegate->SetCapsLockEnabled(true); |
610 EXPECT_FALSE(GetController()->Process( | 592 EXPECT_FALSE(GetController()->Process( |
611 ui::Accelerator(ui::VKEY_RSHIFT, ui::EF_NONE))); | 593 ui::Accelerator(ui::VKEY_RSHIFT, ui::EF_NONE))); |
| 594 EXPECT_TRUE(delegate->IsCapsLockEnabled()); |
612 EXPECT_TRUE(GetController()->Process( | 595 EXPECT_TRUE(GetController()->Process( |
613 ReleaseAccelerator(ui::VKEY_LSHIFT, ui::EF_NONE))); | 596 ReleaseAccelerator(ui::VKEY_LSHIFT, ui::EF_NONE))); |
| 597 EXPECT_FALSE(delegate->IsCapsLockEnabled()); |
| 598 delegate->SetCapsLockEnabled(true); |
614 EXPECT_FALSE(GetController()->Process( | 599 EXPECT_FALSE(GetController()->Process( |
615 ui::Accelerator(ui::VKEY_SHIFT, ui::EF_NONE))); | 600 ui::Accelerator(ui::VKEY_SHIFT, ui::EF_NONE))); |
| 601 EXPECT_TRUE(delegate->IsCapsLockEnabled()); |
616 EXPECT_TRUE(GetController()->Process( | 602 EXPECT_TRUE(GetController()->Process( |
617 ReleaseAccelerator(ui::VKEY_RSHIFT, ui::EF_NONE))); | 603 ReleaseAccelerator(ui::VKEY_RSHIFT, ui::EF_NONE))); |
| 604 EXPECT_FALSE(delegate->IsCapsLockEnabled()); |
618 | 605 |
619 // Do not handle when a shift pressed with other keys. | 606 // Do not handle when a shift pressed with other keys. |
| 607 delegate->SetCapsLockEnabled(true); |
| 608 EXPECT_FALSE(GetController()->Process( |
| 609 ui::Accelerator(ui::VKEY_A, ui::EF_SHIFT_DOWN))); |
| 610 EXPECT_TRUE(delegate->IsCapsLockEnabled()); |
620 EXPECT_FALSE(GetController()->Process( | 611 EXPECT_FALSE(GetController()->Process( |
621 ReleaseAccelerator(ui::VKEY_A, ui::EF_SHIFT_DOWN))); | 612 ReleaseAccelerator(ui::VKEY_A, ui::EF_SHIFT_DOWN))); |
| 613 EXPECT_TRUE(delegate->IsCapsLockEnabled()); |
622 } | 614 } |
623 // ToggleCapsLock | 615 // ToggleCapsLock |
624 { | 616 { |
625 EXPECT_FALSE(GetController()->Process( | 617 CapsLockDelegate* delegate = Shell::GetInstance()->caps_lock_delegate(); |
626 ui::Accelerator(ui::VKEY_LWIN, ui::EF_ALT_DOWN))); | 618 delegate->SetCapsLockEnabled(true); |
627 DummyCapsLockDelegate* delegate = new DummyCapsLockDelegate(false); | 619 EXPECT_TRUE(delegate->IsCapsLockEnabled()); |
628 GetController()->SetCapsLockDelegate( | |
629 scoped_ptr<CapsLockDelegate>(delegate).Pass()); | |
630 EXPECT_EQ(0, delegate->handle_caps_lock_count()); | |
631 EXPECT_FALSE(GetController()->Process( | |
632 ui::Accelerator(ui::VKEY_LWIN, ui::EF_ALT_DOWN))); | |
633 EXPECT_EQ(1, delegate->handle_caps_lock_count()); | |
634 } | |
635 { | |
636 DummyCapsLockDelegate* delegate = new DummyCapsLockDelegate(true); | |
637 GetController()->SetCapsLockDelegate( | |
638 scoped_ptr<CapsLockDelegate>(delegate).Pass()); | |
639 EXPECT_EQ(0, delegate->handle_caps_lock_count()); | |
640 EXPECT_TRUE(GetController()->Process( | 620 EXPECT_TRUE(GetController()->Process( |
641 ui::Accelerator(ui::VKEY_LWIN, ui::EF_ALT_DOWN))); | 621 ui::Accelerator(ui::VKEY_LWIN, ui::EF_ALT_DOWN))); |
642 EXPECT_EQ(1, delegate->handle_caps_lock_count()); | 622 EXPECT_FALSE(delegate->IsCapsLockEnabled()); |
| 623 EXPECT_TRUE(GetController()->Process( |
| 624 ui::Accelerator(ui::VKEY_LWIN, ui::EF_ALT_DOWN))); |
| 625 EXPECT_TRUE(delegate->IsCapsLockEnabled()); |
643 } | 626 } |
644 // Volume | 627 // Volume |
645 const ui::Accelerator f8(ui::VKEY_F8, ui::EF_NONE); | 628 const ui::Accelerator f8(ui::VKEY_F8, ui::EF_NONE); |
646 const ui::Accelerator f9(ui::VKEY_F9, ui::EF_NONE); | 629 const ui::Accelerator f9(ui::VKEY_F9, ui::EF_NONE); |
647 const ui::Accelerator f10(ui::VKEY_F10, ui::EF_NONE); | 630 const ui::Accelerator f10(ui::VKEY_F10, ui::EF_NONE); |
648 { | 631 { |
649 EXPECT_TRUE(GetController()->Process(f8)); | 632 EXPECT_TRUE(GetController()->Process(f8)); |
650 EXPECT_TRUE(GetController()->Process(f9)); | 633 EXPECT_TRUE(GetController()->Process(f9)); |
651 EXPECT_TRUE(GetController()->Process(f10)); | 634 EXPECT_TRUE(GetController()->Process(f10)); |
652 DummyVolumeControlDelegate* delegate = | 635 DummyVolumeControlDelegate* delegate = |
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1007 EXPECT_FALSE(GetController()->IsReservedAccelerator( | 990 EXPECT_FALSE(GetController()->IsReservedAccelerator( |
1008 ui::Accelerator(ui::VKEY_PRINT, ui::EF_NONE))); | 991 ui::Accelerator(ui::VKEY_PRINT, ui::EF_NONE))); |
1009 EXPECT_FALSE(GetController()->IsReservedAccelerator( | 992 EXPECT_FALSE(GetController()->IsReservedAccelerator( |
1010 ui::Accelerator(ui::VKEY_TAB, ui::EF_NONE))); | 993 ui::Accelerator(ui::VKEY_TAB, ui::EF_NONE))); |
1011 EXPECT_FALSE(GetController()->IsReservedAccelerator( | 994 EXPECT_FALSE(GetController()->IsReservedAccelerator( |
1012 ui::Accelerator(ui::VKEY_A, ui::EF_NONE))); | 995 ui::Accelerator(ui::VKEY_A, ui::EF_NONE))); |
1013 } | 996 } |
1014 | 997 |
1015 } // namespace test | 998 } // namespace test |
1016 } // namespace ash | 999 } // namespace ash |
OLD | NEW |