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

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

Issue 10694118: Add shortcuts for keyboard brightness (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review fix Created 8 years, 5 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/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/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"
11 #include "ash/shell_window_ids.h" 11 #include "ash/shell_window_ids.h"
12 #include "ash/system/brightness/brightness_control_delegate.h" 12 #include "ash/system/brightness/brightness_control_delegate.h"
13 #include "ash/system/keyboard_brightness/keyboard_brightness_control_delegate.h"
13 #include "ash/test/ash_test_base.h" 14 #include "ash/test/ash_test_base.h"
14 #include "ash/test/test_shell_delegate.h" 15 #include "ash/test/test_shell_delegate.h"
15 #include "ash/volume_control_delegate.h" 16 #include "ash/volume_control_delegate.h"
16 #include "ash/wm/window_util.h" 17 #include "ash/wm/window_util.h"
17 #include "ui/aura/event.h" 18 #include "ui/aura/event.h"
18 #include "ui/aura/root_window.h" 19 #include "ui/aura/root_window.h"
19 #include "ui/aura/test/test_window_delegate.h" 20 #include "ui/aura/test/test_window_delegate.h"
20 #include "ui/aura/test/test_windows.h" 21 #include "ui/aura/test/test_windows.h"
21 #include "ui/aura/window.h" 22 #include "ui/aura/window.h"
22 23
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 private: 260 private:
260 const bool consume_; 261 const bool consume_;
261 int handle_next_ime_count_; 262 int handle_next_ime_count_;
262 int handle_previous_ime_count_; 263 int handle_previous_ime_count_;
263 int handle_switch_ime_count_; 264 int handle_switch_ime_count_;
264 ui::Accelerator last_accelerator_; 265 ui::Accelerator last_accelerator_;
265 266
266 DISALLOW_COPY_AND_ASSIGN(DummyImeControlDelegate); 267 DISALLOW_COPY_AND_ASSIGN(DummyImeControlDelegate);
267 }; 268 };
268 269
270 class DummyKeyboardBrightnessControlDelegate
271 : public KeyboardBrightnessControlDelegate {
272 public:
273 explicit DummyKeyboardBrightnessControlDelegate(bool consume)
274 : consume_(consume),
275 handle_keyboard_brightness_down_count_(0),
276 handle_keyboard_brightness_up_count_(0) {
277 }
278 virtual ~DummyKeyboardBrightnessControlDelegate() {}
279
280 virtual bool HandleKeyboardBrightnessDown(
281 const ui::Accelerator& accelerator) OVERRIDE {
282 ++handle_keyboard_brightness_down_count_;
283 last_accelerator_ = accelerator;
284 return consume_;
285 }
286
287 virtual bool HandleKeyboardBrightnessUp(
288 const ui::Accelerator& accelerator) OVERRIDE {
289 ++handle_keyboard_brightness_up_count_;
290 last_accelerator_ = accelerator;
291 return consume_;
292 }
293
294 int handle_keyboard_brightness_down_count() const {
295 return handle_keyboard_brightness_down_count_;
296 }
297
298 int handle_keyboard_brightness_up_count() const {
299 return handle_keyboard_brightness_up_count_;
300 }
301
302 const ui::Accelerator& last_accelerator() const {
303 return last_accelerator_;
304 }
305
306 private:
307 const bool consume_;
308 int handle_keyboard_brightness_down_count_;
309 int handle_keyboard_brightness_up_count_;
310 ui::Accelerator last_accelerator_;
311
312 DISALLOW_COPY_AND_ASSIGN(DummyKeyboardBrightnessControlDelegate);
313 };
314
269 bool TestTarget::AcceleratorPressed(const ui::Accelerator& accelerator) { 315 bool TestTarget::AcceleratorPressed(const ui::Accelerator& accelerator) {
270 ++accelerator_pressed_count_; 316 ++accelerator_pressed_count_;
271 return true; 317 return true;
272 } 318 }
273 319
274 bool TestTarget::CanHandleAccelerators() const { 320 bool TestTarget::CanHandleAccelerators() const {
275 return true; 321 return true;
276 } 322 }
277 323
278 } // namespace 324 } // namespace
(...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after
705 EXPECT_EQ(0, delegate->handle_brightness_down_count()); 751 EXPECT_EQ(0, delegate->handle_brightness_down_count());
706 EXPECT_TRUE(GetController()->Process(brightness_down)); 752 EXPECT_TRUE(GetController()->Process(brightness_down));
707 EXPECT_EQ(1, delegate->handle_brightness_down_count()); 753 EXPECT_EQ(1, delegate->handle_brightness_down_count());
708 EXPECT_EQ(brightness_down, delegate->last_accelerator()); 754 EXPECT_EQ(brightness_down, delegate->last_accelerator());
709 EXPECT_EQ(0, delegate->handle_brightness_up_count()); 755 EXPECT_EQ(0, delegate->handle_brightness_up_count());
710 EXPECT_TRUE(GetController()->Process(brightness_up)); 756 EXPECT_TRUE(GetController()->Process(brightness_up));
711 EXPECT_EQ(1, delegate->handle_brightness_up_count()); 757 EXPECT_EQ(1, delegate->handle_brightness_up_count());
712 EXPECT_EQ(brightness_up, delegate->last_accelerator()); 758 EXPECT_EQ(brightness_up, delegate->last_accelerator());
713 } 759 }
714 #endif 760 #endif
761
762 // Keyboard brightness
763 const ui::Accelerator alt_f6(ui::VKEY_F6, ui::EF_ALT_DOWN);
764 const ui::Accelerator alt_f7(ui::VKEY_F7, ui::EF_ALT_DOWN);
765 {
766 EXPECT_FALSE(GetController()->Process(alt_f6));
767 EXPECT_FALSE(GetController()->Process(alt_f7));
768 DummyKeyboardBrightnessControlDelegate* delegate =
769 new DummyKeyboardBrightnessControlDelegate(false);
770 GetController()->SetKeyboardBrightnessControlDelegate(
771 scoped_ptr<KeyboardBrightnessControlDelegate>(delegate).Pass());
772 EXPECT_EQ(0, delegate->handle_keyboard_brightness_down_count());
773 EXPECT_FALSE(GetController()->Process(alt_f6));
774 EXPECT_EQ(1, delegate->handle_keyboard_brightness_down_count());
775 EXPECT_EQ(alt_f6, delegate->last_accelerator());
776 EXPECT_EQ(0, delegate->handle_keyboard_brightness_up_count());
777 EXPECT_FALSE(GetController()->Process(alt_f7));
778 EXPECT_EQ(1, delegate->handle_keyboard_brightness_up_count());
779 EXPECT_EQ(alt_f7, delegate->last_accelerator());
780 }
781 {
782 DummyKeyboardBrightnessControlDelegate* delegate =
783 new DummyKeyboardBrightnessControlDelegate(true);
784 GetController()->SetKeyboardBrightnessControlDelegate(
785 scoped_ptr<KeyboardBrightnessControlDelegate>(delegate).Pass());
786 EXPECT_EQ(0, delegate->handle_keyboard_brightness_down_count());
787 EXPECT_TRUE(GetController()->Process(alt_f6));
788 EXPECT_EQ(1, delegate->handle_keyboard_brightness_down_count());
789 EXPECT_EQ(alt_f6, delegate->last_accelerator());
790 EXPECT_EQ(0, delegate->handle_keyboard_brightness_up_count());
791 EXPECT_TRUE(GetController()->Process(alt_f7));
792 EXPECT_EQ(1, delegate->handle_keyboard_brightness_up_count());
793 EXPECT_EQ(alt_f7, delegate->last_accelerator());
794 }
795
715 #if !defined(NDEBUG) 796 #if !defined(NDEBUG)
716 // RotateScreen 797 // RotateScreen
717 EXPECT_TRUE(GetController()->Process( 798 EXPECT_TRUE(GetController()->Process(
718 ui::Accelerator(ui::VKEY_HOME, ui::EF_CONTROL_DOWN))); 799 ui::Accelerator(ui::VKEY_HOME, ui::EF_CONTROL_DOWN)));
719 // ToggleDesktopBackgroundMode 800 // ToggleDesktopBackgroundMode
720 EXPECT_TRUE(GetController()->Process( 801 EXPECT_TRUE(GetController()->Process(
721 ui::Accelerator(ui::VKEY_B, ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN))); 802 ui::Accelerator(ui::VKEY_B, ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN)));
722 #if !defined(OS_LINUX) 803 #if !defined(OS_LINUX)
723 // ToggleDesktopFullScreen (not implemented yet on Linux) 804 // ToggleDesktopFullScreen (not implemented yet on Linux)
724 EXPECT_TRUE(GetController()->Process( 805 EXPECT_TRUE(GetController()->Process(
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
882 EXPECT_TRUE(GetController()->IsReservedAccelerator( 963 EXPECT_TRUE(GetController()->IsReservedAccelerator(
883 ui::Accelerator(ui::VKEY_TAB, ui::EF_ALT_DOWN))); 964 ui::Accelerator(ui::VKEY_TAB, ui::EF_ALT_DOWN)));
884 EXPECT_FALSE(GetController()->IsReservedAccelerator( 965 EXPECT_FALSE(GetController()->IsReservedAccelerator(
885 ui::Accelerator(ui::VKEY_F5, ui::EF_SHIFT_DOWN))); 966 ui::Accelerator(ui::VKEY_F5, ui::EF_SHIFT_DOWN)));
886 EXPECT_TRUE(GetController()->IsReservedAccelerator( 967 EXPECT_TRUE(GetController()->IsReservedAccelerator(
887 ui::Accelerator(ui::VKEY_TAB, ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN))); 968 ui::Accelerator(ui::VKEY_TAB, ui::EF_SHIFT_DOWN | ui::EF_ALT_DOWN)));
888 } 969 }
889 970
890 } // namespace test 971 } // namespace test
891 } // namespace ash 972 } // 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