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

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

Issue 10878058: Move functions for controlling Caps Lock to CapsLockDelegate from SystemTrayDelegate. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address comment Created 8 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « ash/accelerators/accelerator_controller.cc ('k') | ash/ash.gyp » ('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/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
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 463 matching lines...) Expand 10 before | Expand all | Expand 10 after
593 // ToggleAppList (with spoken feedback enabled) 569 // ToggleAppList (with spoken feedback enabled)
594 { 570 {
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 // CapsLock
Yusuke Sato 2012/08/27 16:45:39 What is this test for? Testing VKEY_[LR]?SHIFT for
mazda 2012/08/27 16:58:58 This block is testing DISABLE_CAPSLOCK and TOGGLE_
604 { 580 {
581 // Disable Caps Lock
582 CapsLockDelegate* delegate = Shell::GetInstance()->caps_lock_delegate();
583 delegate->SetCapsLockEnabled(true);
584 EXPECT_TRUE(delegate->IsCapsLockEnabled());
605 // Handled only on key release. 585 // Handled only on key release.
606 EXPECT_FALSE(GetController()->Process( 586 EXPECT_FALSE(GetController()->Process(
607 ui::Accelerator(ui::VKEY_LSHIFT, ui::EF_NONE))); 587 ui::Accelerator(ui::VKEY_LSHIFT, ui::EF_NONE)));
588 EXPECT_TRUE(delegate->IsCapsLockEnabled());
608 EXPECT_TRUE(GetController()->Process( 589 EXPECT_TRUE(GetController()->Process(
609 ReleaseAccelerator(ui::VKEY_SHIFT, ui::EF_NONE))); 590 ReleaseAccelerator(ui::VKEY_SHIFT, ui::EF_NONE)));
591 EXPECT_FALSE(delegate->IsCapsLockEnabled());
592 delegate->SetCapsLockEnabled(true);
610 EXPECT_FALSE(GetController()->Process( 593 EXPECT_FALSE(GetController()->Process(
611 ui::Accelerator(ui::VKEY_RSHIFT, ui::EF_NONE))); 594 ui::Accelerator(ui::VKEY_RSHIFT, ui::EF_NONE)));
595 EXPECT_TRUE(delegate->IsCapsLockEnabled());
612 EXPECT_TRUE(GetController()->Process( 596 EXPECT_TRUE(GetController()->Process(
613 ReleaseAccelerator(ui::VKEY_LSHIFT, ui::EF_NONE))); 597 ReleaseAccelerator(ui::VKEY_LSHIFT, ui::EF_NONE)));
598 EXPECT_FALSE(delegate->IsCapsLockEnabled());
599 delegate->SetCapsLockEnabled(true);
614 EXPECT_FALSE(GetController()->Process( 600 EXPECT_FALSE(GetController()->Process(
615 ui::Accelerator(ui::VKEY_SHIFT, ui::EF_NONE))); 601 ui::Accelerator(ui::VKEY_SHIFT, ui::EF_NONE)));
602 EXPECT_TRUE(delegate->IsCapsLockEnabled());
616 EXPECT_TRUE(GetController()->Process( 603 EXPECT_TRUE(GetController()->Process(
617 ReleaseAccelerator(ui::VKEY_RSHIFT, ui::EF_NONE))); 604 ReleaseAccelerator(ui::VKEY_RSHIFT, ui::EF_NONE)));
605 EXPECT_FALSE(delegate->IsCapsLockEnabled());
618 606
619 // Do not handle when a shift pressed with other keys. 607 // Do not handle when a shift pressed with other keys.
608 delegate->SetCapsLockEnabled(true);
609 EXPECT_FALSE(GetController()->Process(
610 ui::Accelerator(ui::VKEY_A, ui::EF_SHIFT_DOWN)));
611 EXPECT_TRUE(delegate->IsCapsLockEnabled());
620 EXPECT_FALSE(GetController()->Process( 612 EXPECT_FALSE(GetController()->Process(
621 ReleaseAccelerator(ui::VKEY_A, ui::EF_SHIFT_DOWN))); 613 ReleaseAccelerator(ui::VKEY_A, ui::EF_SHIFT_DOWN)));
622 } 614 EXPECT_TRUE(delegate->IsCapsLockEnabled());
623 // ToggleCapsLock 615
624 { 616 // ToggleCapsLock
625 EXPECT_FALSE(GetController()->Process(
626 ui::Accelerator(ui::VKEY_LWIN, ui::EF_ALT_DOWN)));
627 DummyCapsLockDelegate* delegate = new DummyCapsLockDelegate(false);
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( 617 EXPECT_TRUE(GetController()->Process(
641 ui::Accelerator(ui::VKEY_LWIN, ui::EF_ALT_DOWN))); 618 ui::Accelerator(ui::VKEY_LWIN, ui::EF_ALT_DOWN)));
642 EXPECT_EQ(1, delegate->handle_caps_lock_count()); 619 EXPECT_FALSE(delegate->IsCapsLockEnabled());
620 EXPECT_TRUE(GetController()->Process(
621 ui::Accelerator(ui::VKEY_LWIN, ui::EF_ALT_DOWN)));
622 EXPECT_TRUE(delegate->IsCapsLockEnabled());
643 } 623 }
644 // Volume 624 // Volume
645 const ui::Accelerator f8(ui::VKEY_F8, ui::EF_NONE); 625 const ui::Accelerator f8(ui::VKEY_F8, ui::EF_NONE);
646 const ui::Accelerator f9(ui::VKEY_F9, ui::EF_NONE); 626 const ui::Accelerator f9(ui::VKEY_F9, ui::EF_NONE);
647 const ui::Accelerator f10(ui::VKEY_F10, ui::EF_NONE); 627 const ui::Accelerator f10(ui::VKEY_F10, ui::EF_NONE);
648 { 628 {
649 EXPECT_TRUE(GetController()->Process(f8)); 629 EXPECT_TRUE(GetController()->Process(f8));
650 EXPECT_TRUE(GetController()->Process(f9)); 630 EXPECT_TRUE(GetController()->Process(f9));
651 EXPECT_TRUE(GetController()->Process(f10)); 631 EXPECT_TRUE(GetController()->Process(f10));
652 DummyVolumeControlDelegate* delegate = 632 DummyVolumeControlDelegate* delegate =
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after
1007 EXPECT_FALSE(GetController()->IsReservedAccelerator( 987 EXPECT_FALSE(GetController()->IsReservedAccelerator(
1008 ui::Accelerator(ui::VKEY_PRINT, ui::EF_NONE))); 988 ui::Accelerator(ui::VKEY_PRINT, ui::EF_NONE)));
1009 EXPECT_FALSE(GetController()->IsReservedAccelerator( 989 EXPECT_FALSE(GetController()->IsReservedAccelerator(
1010 ui::Accelerator(ui::VKEY_TAB, ui::EF_NONE))); 990 ui::Accelerator(ui::VKEY_TAB, ui::EF_NONE)));
1011 EXPECT_FALSE(GetController()->IsReservedAccelerator( 991 EXPECT_FALSE(GetController()->IsReservedAccelerator(
1012 ui::Accelerator(ui::VKEY_A, ui::EF_NONE))); 992 ui::Accelerator(ui::VKEY_A, ui::EF_NONE)));
1013 } 993 }
1014 994
1015 } // namespace test 995 } // namespace test
1016 } // namespace ash 996 } // namespace ash
OLDNEW
« no previous file with comments | « ash/accelerators/accelerator_controller.cc ('k') | ash/ash.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698