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
3 // found in the LICENSE file.
5 #include "ash/accelerators/accelerator_controller.h"
6 #include "ash/accelerators/accelerator_table.h"
7 #include "ash/caps_lock_delegate.h"
8 #include "ash/display/display_manager.h"
9 #include "ash/ime_control_delegate.h"
10 #include "ash/screenshot_delegate.h"
11 #include "ash/shell.h"
12 #include "ash/shell_window_ids.h"
13 #include "ash/system/brightness/brightness_control_delegate.h"
14 #include "ash/system/keyboard_brightness/keyboard_brightness_control_delegate.h"
15 #include "ash/system/tray/system_tray_delegate.h"
16 #include "ash/test/ash_test_base.h"
17 #include "ash/test/test_shell_delegate.h"
18 #include "ash/volume_control_delegate.h"
19 #include "ash/wm/window_util.h"
20 #include "ui/aura/root_window.h"
21 #include "ui/aura/test/test_window_delegate.h"
22 #include "ui/aura/test/test_windows.h"
23 #include "ui/aura/window.h"
24 #include "ui/base/events/event.h"
28 #include "ui/base/x/x11_util.h"
35 class TestTarget
: public ui::AcceleratorTarget
{
37 TestTarget() : accelerator_pressed_count_(0) {};
38 virtual ~TestTarget() {};
40 int accelerator_pressed_count() const {
41 return accelerator_pressed_count_
;
44 void set_accelerator_pressed_count(int accelerator_pressed_count
) {
45 accelerator_pressed_count_
= accelerator_pressed_count
;
48 // Overridden from ui::AcceleratorTarget:
49 virtual bool AcceleratorPressed(const ui::Accelerator
& accelerator
) OVERRIDE
;
50 virtual bool CanHandleAccelerators() const OVERRIDE
;
53 int accelerator_pressed_count_
;
55 DISALLOW_COPY_AND_ASSIGN(TestTarget
);
58 class ReleaseAccelerator
: public ui::Accelerator
{
60 ReleaseAccelerator(ui::KeyboardCode keycode
, int modifiers
)
61 : ui::Accelerator(keycode
, modifiers
) {
62 set_type(ui::ET_KEY_RELEASED
);
66 class DummyScreenshotDelegate
: public ScreenshotDelegate
{
68 DummyScreenshotDelegate()
69 : handle_take_screenshot_count_(0) {
71 virtual ~DummyScreenshotDelegate() {}
73 // Overridden from ScreenshotDelegate:
74 virtual void HandleTakeScreenshotForAllRootWindows() OVERRIDE
{
75 ++handle_take_screenshot_count_
;
78 virtual void HandleTakePartialScreenshot(
79 aura::Window
* window
, const gfx::Rect
& rect
) OVERRIDE
{
82 virtual bool CanTakeScreenshot() OVERRIDE
{
86 int handle_take_screenshot_count() const {
87 return handle_take_screenshot_count_
;
91 int handle_take_screenshot_count_
;
93 DISALLOW_COPY_AND_ASSIGN(DummyScreenshotDelegate
);
96 class DummyVolumeControlDelegate
: public VolumeControlDelegate
{
98 explicit DummyVolumeControlDelegate(bool consume
)
100 handle_volume_mute_count_(0),
101 handle_volume_down_count_(0),
102 handle_volume_up_count_(0) {
104 virtual ~DummyVolumeControlDelegate() {}
106 virtual bool HandleVolumeMute(const ui::Accelerator
& accelerator
) OVERRIDE
{
107 ++handle_volume_mute_count_
;
108 last_accelerator_
= accelerator
;
111 virtual bool HandleVolumeDown(const ui::Accelerator
& accelerator
) OVERRIDE
{
112 ++handle_volume_down_count_
;
113 last_accelerator_
= accelerator
;
116 virtual bool HandleVolumeUp(const ui::Accelerator
& accelerator
) OVERRIDE
{
117 ++handle_volume_up_count_
;
118 last_accelerator_
= accelerator
;
121 virtual void SetVolumePercent(double percent
) OVERRIDE
{
123 virtual bool IsAudioMuted() const OVERRIDE
{
126 virtual void SetAudioMuted(bool muted
) OVERRIDE
{
128 virtual float GetVolumeLevel() const OVERRIDE
{
131 virtual void SetVolumeLevel(float level
) OVERRIDE
{
134 int handle_volume_mute_count() const {
135 return handle_volume_mute_count_
;
137 int handle_volume_down_count() const {
138 return handle_volume_down_count_
;
140 int handle_volume_up_count() const {
141 return handle_volume_up_count_
;
143 const ui::Accelerator
& last_accelerator() const {
144 return last_accelerator_
;
149 int handle_volume_mute_count_
;
150 int handle_volume_down_count_
;
151 int handle_volume_up_count_
;
152 ui::Accelerator last_accelerator_
;
154 DISALLOW_COPY_AND_ASSIGN(DummyVolumeControlDelegate
);
157 class DummyBrightnessControlDelegate
: public BrightnessControlDelegate
{
159 explicit DummyBrightnessControlDelegate(bool consume
)
161 handle_brightness_down_count_(0),
162 handle_brightness_up_count_(0) {
164 virtual ~DummyBrightnessControlDelegate() {}
166 virtual bool HandleBrightnessDown(
167 const ui::Accelerator
& accelerator
) OVERRIDE
{
168 ++handle_brightness_down_count_
;
169 last_accelerator_
= accelerator
;
172 virtual bool HandleBrightnessUp(const ui::Accelerator
& accelerator
) OVERRIDE
{
173 ++handle_brightness_up_count_
;
174 last_accelerator_
= accelerator
;
177 virtual void SetBrightnessPercent(double percent
, bool gradual
) OVERRIDE
{}
178 virtual void GetBrightnessPercent(
179 const base::Callback
<void(double)>& callback
) OVERRIDE
{
183 int handle_brightness_down_count() const {
184 return handle_brightness_down_count_
;
186 int handle_brightness_up_count() const {
187 return handle_brightness_up_count_
;
189 const ui::Accelerator
& last_accelerator() const {
190 return last_accelerator_
;
195 int handle_brightness_down_count_
;
196 int handle_brightness_up_count_
;
197 ui::Accelerator last_accelerator_
;
199 DISALLOW_COPY_AND_ASSIGN(DummyBrightnessControlDelegate
);
202 class DummyImeControlDelegate
: public ImeControlDelegate
{
204 explicit DummyImeControlDelegate(bool consume
)
206 handle_next_ime_count_(0),
207 handle_previous_ime_count_(0),
208 handle_switch_ime_count_(0) {
210 virtual ~DummyImeControlDelegate() {}
212 virtual bool HandleNextIme() OVERRIDE
{
213 ++handle_next_ime_count_
;
216 virtual bool HandlePreviousIme() OVERRIDE
{
217 ++handle_previous_ime_count_
;
220 virtual bool HandleSwitchIme(const ui::Accelerator
& accelerator
) OVERRIDE
{
221 ++handle_switch_ime_count_
;
222 last_accelerator_
= accelerator
;
226 int handle_next_ime_count() const {
227 return handle_next_ime_count_
;
229 int handle_previous_ime_count() const {
230 return handle_previous_ime_count_
;
232 int handle_switch_ime_count() const {
233 return handle_switch_ime_count_
;
235 const ui::Accelerator
& last_accelerator() const {
236 return last_accelerator_
;
238 ui::Accelerator
RemapAccelerator(
239 const ui::Accelerator
& accelerator
) {
240 return ui::Accelerator(accelerator
);
245 int handle_next_ime_count_
;
246 int handle_previous_ime_count_
;
247 int handle_switch_ime_count_
;
248 ui::Accelerator last_accelerator_
;
250 DISALLOW_COPY_AND_ASSIGN(DummyImeControlDelegate
);
253 class DummyKeyboardBrightnessControlDelegate
254 : public KeyboardBrightnessControlDelegate
{
256 explicit DummyKeyboardBrightnessControlDelegate(bool consume
)
258 handle_keyboard_brightness_down_count_(0),
259 handle_keyboard_brightness_up_count_(0) {
261 virtual ~DummyKeyboardBrightnessControlDelegate() {}
263 virtual bool HandleKeyboardBrightnessDown(
264 const ui::Accelerator
& accelerator
) OVERRIDE
{
265 ++handle_keyboard_brightness_down_count_
;
266 last_accelerator_
= accelerator
;
270 virtual bool HandleKeyboardBrightnessUp(
271 const ui::Accelerator
& accelerator
) OVERRIDE
{
272 ++handle_keyboard_brightness_up_count_
;
273 last_accelerator_
= accelerator
;
277 int handle_keyboard_brightness_down_count() const {
278 return handle_keyboard_brightness_down_count_
;
281 int handle_keyboard_brightness_up_count() const {
282 return handle_keyboard_brightness_up_count_
;
285 const ui::Accelerator
& last_accelerator() const {
286 return last_accelerator_
;
291 int handle_keyboard_brightness_down_count_
;
292 int handle_keyboard_brightness_up_count_
;
293 ui::Accelerator last_accelerator_
;
295 DISALLOW_COPY_AND_ASSIGN(DummyKeyboardBrightnessControlDelegate
);
298 bool TestTarget::AcceleratorPressed(const ui::Accelerator
& accelerator
) {
299 ++accelerator_pressed_count_
;
303 bool TestTarget::CanHandleAccelerators() const {
309 class AcceleratorControllerTest
: public test::AshTestBase
{
311 AcceleratorControllerTest() {};
312 virtual ~AcceleratorControllerTest() {};
315 void EnableInternalDisplay() {
316 Shell::GetInstance()->display_manager()->
317 SetFirstDisplayAsInternalDisplayForTest();
320 static AcceleratorController
* GetController();
321 static bool ProcessWithContext(const ui::Accelerator
& accelerator
);
324 DISALLOW_COPY_AND_ASSIGN(AcceleratorControllerTest
);
327 AcceleratorController
* AcceleratorControllerTest::GetController() {
328 return Shell::GetInstance()->accelerator_controller();
331 bool AcceleratorControllerTest::ProcessWithContext(
332 const ui::Accelerator
& accelerator
) {
333 AcceleratorController
* controller
= GetController();
334 controller
->context()->UpdateContext(accelerator
);
335 return controller
->Process(accelerator
);
338 TEST_F(AcceleratorControllerTest
, Register
) {
339 const ui::Accelerator
accelerator_a(ui::VKEY_A
, ui::EF_NONE
);
341 GetController()->Register(accelerator_a
, &target
);
343 // The registered accelerator is processed.
344 EXPECT_TRUE(ProcessWithContext(accelerator_a
));
345 EXPECT_EQ(1, target
.accelerator_pressed_count());
348 TEST_F(AcceleratorControllerTest
, RegisterMultipleTarget
) {
349 const ui::Accelerator
accelerator_a(ui::VKEY_A
, ui::EF_NONE
);
351 GetController()->Register(accelerator_a
, &target1
);
353 GetController()->Register(accelerator_a
, &target2
);
355 // If multiple targets are registered with the same accelerator, the target
356 // registered later processes the accelerator.
357 EXPECT_TRUE(ProcessWithContext(accelerator_a
));
358 EXPECT_EQ(0, target1
.accelerator_pressed_count());
359 EXPECT_EQ(1, target2
.accelerator_pressed_count());
362 TEST_F(AcceleratorControllerTest
, Unregister
) {
363 const ui::Accelerator
accelerator_a(ui::VKEY_A
, ui::EF_NONE
);
365 GetController()->Register(accelerator_a
, &target
);
366 const ui::Accelerator
accelerator_b(ui::VKEY_B
, ui::EF_NONE
);
367 GetController()->Register(accelerator_b
, &target
);
369 // Unregistering a different accelerator does not affect the other
371 GetController()->Unregister(accelerator_b
, &target
);
372 EXPECT_TRUE(ProcessWithContext(accelerator_a
));
373 EXPECT_EQ(1, target
.accelerator_pressed_count());
375 // The unregistered accelerator is no longer processed.
376 target
.set_accelerator_pressed_count(0);
377 GetController()->Unregister(accelerator_a
, &target
);
378 EXPECT_FALSE(ProcessWithContext(accelerator_a
));
379 EXPECT_EQ(0, target
.accelerator_pressed_count());
382 TEST_F(AcceleratorControllerTest
, UnregisterAll
) {
383 const ui::Accelerator
accelerator_a(ui::VKEY_A
, ui::EF_NONE
);
385 GetController()->Register(accelerator_a
, &target1
);
386 const ui::Accelerator
accelerator_b(ui::VKEY_B
, ui::EF_NONE
);
387 GetController()->Register(accelerator_b
, &target1
);
388 const ui::Accelerator
accelerator_c(ui::VKEY_C
, ui::EF_NONE
);
390 GetController()->Register(accelerator_c
, &target2
);
391 GetController()->UnregisterAll(&target1
);
393 // All the accelerators registered for |target1| are no longer processed.
394 EXPECT_FALSE(ProcessWithContext(accelerator_a
));
395 EXPECT_FALSE(ProcessWithContext(accelerator_b
));
396 EXPECT_EQ(0, target1
.accelerator_pressed_count());
398 // UnregisterAll with a different target does not affect the other target.
399 EXPECT_TRUE(ProcessWithContext(accelerator_c
));
400 EXPECT_EQ(1, target2
.accelerator_pressed_count());
403 TEST_F(AcceleratorControllerTest
, Process
) {
404 const ui::Accelerator
accelerator_a(ui::VKEY_A
, ui::EF_NONE
);
406 GetController()->Register(accelerator_a
, &target1
);
408 // The registered accelerator is processed.
409 EXPECT_TRUE(ProcessWithContext(accelerator_a
));
410 EXPECT_EQ(1, target1
.accelerator_pressed_count());
412 // The non-registered accelerator is not processed.
413 const ui::Accelerator
accelerator_b(ui::VKEY_B
, ui::EF_NONE
);
414 EXPECT_FALSE(ProcessWithContext(accelerator_b
));
417 TEST_F(AcceleratorControllerTest
, IsRegistered
) {
418 const ui::Accelerator
accelerator_a(ui::VKEY_A
, ui::EF_NONE
);
419 const ui::Accelerator
accelerator_shift_a(ui::VKEY_A
, ui::EF_SHIFT_DOWN
);
421 GetController()->Register(accelerator_a
, &target
);
422 EXPECT_TRUE(GetController()->IsRegistered(accelerator_a
));
423 EXPECT_FALSE(GetController()->IsRegistered(accelerator_shift_a
));
424 GetController()->UnregisterAll(&target
);
425 EXPECT_FALSE(GetController()->IsRegistered(accelerator_a
));
428 TEST_F(AcceleratorControllerTest
, WindowSnap
) {
429 scoped_ptr
<aura::Window
> window(
430 CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20)));
431 const ui::Accelerator dummy
;
433 wm::ActivateWindow(window
.get());
436 GetController()->PerformAction(WINDOW_SNAP_LEFT
, dummy
);
437 gfx::Rect snap_left
= window
->bounds();
438 GetController()->PerformAction(WINDOW_SNAP_LEFT
, dummy
);
439 EXPECT_NE(window
->bounds().ToString(), snap_left
.ToString());
441 // It should cycle back to the first snapped position.
442 GetController()->PerformAction(WINDOW_SNAP_LEFT
, dummy
);
443 EXPECT_EQ(window
->bounds().ToString(), snap_left
.ToString());
446 GetController()->PerformAction(WINDOW_SNAP_RIGHT
, dummy
);
447 gfx::Rect snap_right
= window
->bounds();
448 GetController()->PerformAction(WINDOW_SNAP_RIGHT
, dummy
);
449 EXPECT_NE(window
->bounds().ToString(), snap_right
.ToString());
451 // It should cycle back to the first snapped position.
452 GetController()->PerformAction(WINDOW_SNAP_RIGHT
, dummy
);
453 EXPECT_EQ(window
->bounds().ToString(), snap_right
.ToString());
456 gfx::Rect normal_bounds
= window
->bounds();
458 GetController()->PerformAction(TOGGLE_MAXIMIZED
, dummy
);
459 EXPECT_TRUE(wm::IsWindowMaximized(window
.get()));
460 EXPECT_NE(normal_bounds
.ToString(), window
->bounds().ToString());
462 GetController()->PerformAction(TOGGLE_MAXIMIZED
, dummy
);
463 EXPECT_FALSE(wm::IsWindowMaximized(window
.get()));
464 EXPECT_EQ(normal_bounds
.ToString(), window
->bounds().ToString());
466 GetController()->PerformAction(TOGGLE_MAXIMIZED
, dummy
);
467 GetController()->PerformAction(WINDOW_SNAP_LEFT
, dummy
);
468 EXPECT_FALSE(wm::IsWindowMaximized(window
.get()));
470 GetController()->PerformAction(TOGGLE_MAXIMIZED
, dummy
);
471 GetController()->PerformAction(WINDOW_SNAP_RIGHT
, dummy
);
472 EXPECT_FALSE(wm::IsWindowMaximized(window
.get()));
474 GetController()->PerformAction(TOGGLE_MAXIMIZED
, dummy
);
475 EXPECT_TRUE(wm::IsWindowMaximized(window
.get()));
476 GetController()->PerformAction(WINDOW_MINIMIZE
, dummy
);
477 EXPECT_FALSE(wm::IsWindowMaximized(window
.get()));
478 EXPECT_TRUE(wm::IsWindowMinimized(window
.get()));
479 wm::RestoreWindow(window
.get());
480 wm::ActivateWindow(window
.get());
483 GetController()->PerformAction(WINDOW_MINIMIZE
, dummy
);
484 EXPECT_TRUE(wm::IsWindowMinimized(window
.get()));
488 TEST_F(AcceleratorControllerTest
, ControllerContext
) {
489 ui::Accelerator
accelerator_a(ui::VKEY_A
, ui::EF_NONE
);
490 ui::Accelerator
accelerator_a2(ui::VKEY_A
, ui::EF_NONE
);
491 ui::Accelerator
accelerator_b(ui::VKEY_B
, ui::EF_NONE
);
493 accelerator_a
.set_type(ui::ET_KEY_PRESSED
);
494 accelerator_a2
.set_type(ui::ET_KEY_RELEASED
);
495 accelerator_b
.set_type(ui::ET_KEY_PRESSED
);
497 EXPECT_FALSE(GetController()->context()->repeated());
498 EXPECT_EQ(ui::ET_UNKNOWN
,
499 GetController()->context()->previous_accelerator().type());
501 GetController()->context()->UpdateContext(accelerator_a
);
502 EXPECT_FALSE(GetController()->context()->repeated());
503 EXPECT_EQ(ui::ET_UNKNOWN
,
504 GetController()->context()->previous_accelerator().type());
506 GetController()->context()->UpdateContext(accelerator_a2
);
507 EXPECT_FALSE(GetController()->context()->repeated());
508 EXPECT_EQ(ui::ET_KEY_PRESSED
,
509 GetController()->context()->previous_accelerator().type());
511 GetController()->context()->UpdateContext(accelerator_a2
);
512 EXPECT_TRUE(GetController()->context()->repeated());
513 EXPECT_EQ(ui::ET_KEY_RELEASED
,
514 GetController()->context()->previous_accelerator().type());
516 GetController()->context()->UpdateContext(accelerator_b
);
517 EXPECT_FALSE(GetController()->context()->repeated());
518 EXPECT_EQ(ui::ET_KEY_RELEASED
,
519 GetController()->context()->previous_accelerator().type());
522 TEST_F(AcceleratorControllerTest
, SuppressToggleMaximized
) {
523 scoped_ptr
<aura::Window
> window(
524 CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20)));
525 wm::ActivateWindow(window
.get());
526 const ui::Accelerator
accelerator(ui::VKEY_A
, ui::EF_NONE
);
527 const ui::Accelerator empty_accelerator
;
529 // Toggling not suppressed.
530 GetController()->context()->UpdateContext(accelerator
);
531 GetController()->PerformAction(TOGGLE_MAXIMIZED
, accelerator
);
532 EXPECT_TRUE(wm::IsWindowMaximized(window
.get()));
534 // The same accelerator - toggling suppressed.
535 GetController()->context()->UpdateContext(accelerator
);
536 GetController()->PerformAction(TOGGLE_MAXIMIZED
, accelerator
);
537 EXPECT_TRUE(wm::IsWindowMaximized(window
.get()));
539 // Suppressed but not for gesture events.
540 GetController()->PerformAction(TOGGLE_MAXIMIZED
, empty_accelerator
);
541 EXPECT_FALSE(wm::IsWindowMaximized(window
.get()));
544 #if defined(OS_WIN) || defined(USE_X11)
545 TEST_F(AcceleratorControllerTest
, ProcessOnce
) {
546 ui::Accelerator
accelerator_a(ui::VKEY_A
, ui::EF_NONE
);
548 GetController()->Register(accelerator_a
, &target
);
550 // The accelerator is processed only once.
552 MSG msg1
= { NULL
, WM_KEYDOWN
, ui::VKEY_A
, 0 };
553 ui::TranslatedKeyEvent
key_event1(msg1
, false);
554 EXPECT_TRUE(Shell::GetPrimaryRootWindow()->AsRootWindowHostDelegate()->
555 OnHostKeyEvent(&key_event1
));
557 MSG msg2
= { NULL
, WM_CHAR
, L
'A', 0 };
558 ui::TranslatedKeyEvent
key_event2(msg2
, true);
559 EXPECT_FALSE(Shell::GetPrimaryRootWindow()->AsRootWindowHostDelegate()->
560 OnHostKeyEvent(&key_event2
));
562 MSG msg3
= { NULL
, WM_KEYUP
, ui::VKEY_A
, 0 };
563 ui::TranslatedKeyEvent
key_event3(msg3
, false);
564 EXPECT_FALSE(Shell::GetPrimaryRootWindow()->AsRootWindowHostDelegate()->
565 OnHostKeyEvent(&key_event3
));
566 #elif defined(USE_X11)
568 ui::InitXKeyEventForTesting(ui::ET_KEY_PRESSED
,
572 ui::TranslatedKeyEvent
key_event1(&key_event
, false);
573 EXPECT_TRUE(Shell::GetPrimaryRootWindow()->AsRootWindowHostDelegate()->
574 OnHostKeyEvent(&key_event1
));
576 ui::TranslatedKeyEvent
key_event2(&key_event
, true);
577 EXPECT_FALSE(Shell::GetPrimaryRootWindow()->AsRootWindowHostDelegate()->
578 OnHostKeyEvent(&key_event2
));
580 ui::InitXKeyEventForTesting(ui::ET_KEY_RELEASED
,
584 ui::TranslatedKeyEvent
key_event3(&key_event
, false);
585 EXPECT_FALSE(Shell::GetPrimaryRootWindow()->AsRootWindowHostDelegate()->
586 OnHostKeyEvent(&key_event3
));
588 EXPECT_EQ(1, target
.accelerator_pressed_count());
592 TEST_F(AcceleratorControllerTest
, GlobalAccelerators
) {
594 EXPECT_TRUE(ProcessWithContext(
595 ui::Accelerator(ui::VKEY_TAB
, ui::EF_SHIFT_DOWN
| ui::EF_ALT_DOWN
)));
597 EXPECT_TRUE(ProcessWithContext(
598 ui::Accelerator(ui::VKEY_TAB
, ui::EF_ALT_DOWN
)));
599 #if defined(OS_CHROMEOS)
601 EXPECT_TRUE(ProcessWithContext(
602 ui::Accelerator(ui::VKEY_MEDIA_LAUNCH_APP1
, ui::EF_SHIFT_DOWN
)));
604 EXPECT_TRUE(ProcessWithContext(
605 ui::Accelerator(ui::VKEY_MEDIA_LAUNCH_APP1
, ui::EF_NONE
)));
607 // Take screenshot / partial screenshot
608 // True should always be returned regardless of the existence of the delegate.
610 EXPECT_TRUE(ProcessWithContext(
611 ui::Accelerator(ui::VKEY_MEDIA_LAUNCH_APP1
, ui::EF_CONTROL_DOWN
)));
612 EXPECT_TRUE(ProcessWithContext(
613 ui::Accelerator(ui::VKEY_PRINT
, ui::EF_NONE
)));
614 EXPECT_TRUE(ProcessWithContext(
615 ui::Accelerator(ui::VKEY_MEDIA_LAUNCH_APP1
,
616 ui::EF_SHIFT_DOWN
| ui::EF_CONTROL_DOWN
)));
617 DummyScreenshotDelegate
* delegate
= new DummyScreenshotDelegate
;
618 GetController()->SetScreenshotDelegate(
619 scoped_ptr
<ScreenshotDelegate
>(delegate
).Pass());
620 EXPECT_EQ(0, delegate
->handle_take_screenshot_count());
621 EXPECT_TRUE(ProcessWithContext(
622 ui::Accelerator(ui::VKEY_MEDIA_LAUNCH_APP1
, ui::EF_CONTROL_DOWN
)));
623 EXPECT_EQ(1, delegate
->handle_take_screenshot_count());
624 EXPECT_TRUE(ProcessWithContext(
625 ui::Accelerator(ui::VKEY_PRINT
, ui::EF_NONE
)));
626 EXPECT_EQ(2, delegate
->handle_take_screenshot_count());
627 EXPECT_TRUE(ProcessWithContext(
628 ui::Accelerator(ui::VKEY_MEDIA_LAUNCH_APP1
,
629 ui::EF_SHIFT_DOWN
| ui::EF_CONTROL_DOWN
)));
630 EXPECT_EQ(2, delegate
->handle_take_screenshot_count());
635 CapsLockDelegate
* delegate
= Shell::GetInstance()->caps_lock_delegate();
636 delegate
->SetCapsLockEnabled(true);
637 EXPECT_TRUE(delegate
->IsCapsLockEnabled());
638 // Handled only on key release.
639 EXPECT_FALSE(ProcessWithContext(
640 ui::Accelerator(ui::VKEY_LSHIFT
, ui::EF_NONE
)));
641 EXPECT_TRUE(delegate
->IsCapsLockEnabled());
642 EXPECT_TRUE(ProcessWithContext(
643 ReleaseAccelerator(ui::VKEY_SHIFT
, ui::EF_NONE
)));
644 EXPECT_FALSE(delegate
->IsCapsLockEnabled());
645 delegate
->SetCapsLockEnabled(true);
646 EXPECT_FALSE(ProcessWithContext(
647 ui::Accelerator(ui::VKEY_RSHIFT
, ui::EF_NONE
)));
648 EXPECT_TRUE(delegate
->IsCapsLockEnabled());
649 EXPECT_TRUE(ProcessWithContext(
650 ReleaseAccelerator(ui::VKEY_LSHIFT
, ui::EF_NONE
)));
651 EXPECT_FALSE(delegate
->IsCapsLockEnabled());
652 delegate
->SetCapsLockEnabled(true);
653 EXPECT_FALSE(ProcessWithContext(
654 ui::Accelerator(ui::VKEY_SHIFT
, ui::EF_NONE
)));
655 EXPECT_TRUE(delegate
->IsCapsLockEnabled());
656 EXPECT_TRUE(ProcessWithContext(
657 ReleaseAccelerator(ui::VKEY_RSHIFT
, ui::EF_NONE
)));
658 EXPECT_FALSE(delegate
->IsCapsLockEnabled());
660 // Do not handle when a shift pressed with other keys.
661 delegate
->SetCapsLockEnabled(true);
662 EXPECT_FALSE(ProcessWithContext(
663 ui::Accelerator(ui::VKEY_A
, ui::EF_SHIFT_DOWN
)));
664 EXPECT_TRUE(delegate
->IsCapsLockEnabled());
665 EXPECT_FALSE(ProcessWithContext(
666 ReleaseAccelerator(ui::VKEY_A
, ui::EF_SHIFT_DOWN
)));
667 EXPECT_TRUE(delegate
->IsCapsLockEnabled());
669 // Do not handle when a shift pressed with other keys, and shift is
671 delegate
->SetCapsLockEnabled(true);
672 EXPECT_FALSE(ProcessWithContext(
673 ui::Accelerator(ui::VKEY_A
, ui::EF_SHIFT_DOWN
)));
674 EXPECT_TRUE(delegate
->IsCapsLockEnabled());
675 EXPECT_FALSE(ProcessWithContext(
676 ReleaseAccelerator(ui::VKEY_LSHIFT
, ui::EF_NONE
)));
677 EXPECT_TRUE(delegate
->IsCapsLockEnabled());
679 EXPECT_FALSE(ProcessWithContext(
680 ui::Accelerator(ui::VKEY_A
, ui::EF_SHIFT_DOWN
)));
681 EXPECT_TRUE(delegate
->IsCapsLockEnabled());
682 EXPECT_FALSE(ProcessWithContext(
683 ReleaseAccelerator(ui::VKEY_SHIFT
, ui::EF_NONE
)));
684 EXPECT_TRUE(delegate
->IsCapsLockEnabled());
686 EXPECT_FALSE(ProcessWithContext(
687 ui::Accelerator(ui::VKEY_A
, ui::EF_SHIFT_DOWN
)));
688 EXPECT_TRUE(delegate
->IsCapsLockEnabled());
689 EXPECT_FALSE(ProcessWithContext(
690 ReleaseAccelerator(ui::VKEY_RSHIFT
, ui::EF_NONE
)));
691 EXPECT_TRUE(delegate
->IsCapsLockEnabled());
693 // Do not consume shift keyup when caps lock is off.
694 delegate
->SetCapsLockEnabled(false);
695 EXPECT_FALSE(ProcessWithContext(
696 ui::Accelerator(ui::VKEY_LSHIFT
, ui::EF_NONE
)));
697 EXPECT_FALSE(ProcessWithContext(
698 ReleaseAccelerator(ui::VKEY_LSHIFT
, ui::EF_NONE
)));
699 EXPECT_FALSE(ProcessWithContext(
700 ui::Accelerator(ui::VKEY_RSHIFT
, ui::EF_NONE
)));
701 EXPECT_FALSE(ProcessWithContext(
702 ReleaseAccelerator(ui::VKEY_RSHIFT
, ui::EF_NONE
)));
703 EXPECT_FALSE(ProcessWithContext(
704 ui::Accelerator(ui::VKEY_SHIFT
, ui::EF_NONE
)));
705 EXPECT_FALSE(ProcessWithContext(
706 ReleaseAccelerator(ui::VKEY_SHIFT
, ui::EF_NONE
)));
710 CapsLockDelegate
* delegate
= Shell::GetInstance()->caps_lock_delegate();
711 delegate
->SetCapsLockEnabled(true);
712 EXPECT_TRUE(delegate
->IsCapsLockEnabled());
713 EXPECT_FALSE(ProcessWithContext(
714 ui::Accelerator(ui::VKEY_LWIN
, ui::EF_ALT_DOWN
)));
715 EXPECT_TRUE(ProcessWithContext(
716 ReleaseAccelerator(ui::VKEY_LWIN
, ui::EF_ALT_DOWN
)));
717 EXPECT_FALSE(delegate
->IsCapsLockEnabled());
718 EXPECT_FALSE(ProcessWithContext(
719 ui::Accelerator(ui::VKEY_LWIN
, ui::EF_ALT_DOWN
)));
720 EXPECT_TRUE(ProcessWithContext(
721 ReleaseAccelerator(ui::VKEY_LWIN
, ui::EF_ALT_DOWN
)));
722 EXPECT_TRUE(delegate
->IsCapsLockEnabled());
724 const ui::Accelerator
volume_mute(ui::VKEY_VOLUME_MUTE
, ui::EF_NONE
);
725 const ui::Accelerator
volume_down(ui::VKEY_VOLUME_DOWN
, ui::EF_NONE
);
726 const ui::Accelerator
volume_up(ui::VKEY_VOLUME_UP
, ui::EF_NONE
);
728 DummyVolumeControlDelegate
* delegate
=
729 new DummyVolumeControlDelegate(false);
730 ash::Shell::GetInstance()->system_tray_delegate()->SetVolumeControlDelegate(
731 scoped_ptr
<VolumeControlDelegate
>(delegate
).Pass());
732 EXPECT_EQ(0, delegate
->handle_volume_mute_count());
733 EXPECT_FALSE(ProcessWithContext(volume_mute
));
734 EXPECT_EQ(1, delegate
->handle_volume_mute_count());
735 EXPECT_EQ(volume_mute
, delegate
->last_accelerator());
736 EXPECT_EQ(0, delegate
->handle_volume_down_count());
737 EXPECT_FALSE(ProcessWithContext(volume_down
));
738 EXPECT_EQ(1, delegate
->handle_volume_down_count());
739 EXPECT_EQ(volume_down
, delegate
->last_accelerator());
740 EXPECT_EQ(0, delegate
->handle_volume_up_count());
741 EXPECT_FALSE(ProcessWithContext(volume_up
));
742 EXPECT_EQ(1, delegate
->handle_volume_up_count());
743 EXPECT_EQ(volume_up
, delegate
->last_accelerator());
746 DummyVolumeControlDelegate
* delegate
= new DummyVolumeControlDelegate(true);
747 ash::Shell::GetInstance()->system_tray_delegate()->SetVolumeControlDelegate(
748 scoped_ptr
<VolumeControlDelegate
>(delegate
).Pass());
749 EXPECT_EQ(0, delegate
->handle_volume_mute_count());
750 EXPECT_TRUE(ProcessWithContext(volume_mute
));
751 EXPECT_EQ(1, delegate
->handle_volume_mute_count());
752 EXPECT_EQ(volume_mute
, delegate
->last_accelerator());
753 EXPECT_EQ(0, delegate
->handle_volume_down_count());
754 EXPECT_TRUE(ProcessWithContext(volume_down
));
755 EXPECT_EQ(1, delegate
->handle_volume_down_count());
756 EXPECT_EQ(volume_down
, delegate
->last_accelerator());
757 EXPECT_EQ(0, delegate
->handle_volume_up_count());
758 EXPECT_TRUE(ProcessWithContext(volume_up
));
759 EXPECT_EQ(1, delegate
->handle_volume_up_count());
760 EXPECT_EQ(volume_up
, delegate
->last_accelerator());
762 #if defined(OS_CHROMEOS)
764 // ui::VKEY_BRIGHTNESS_DOWN/UP are not defined on Windows.
765 const ui::Accelerator
brightness_down(ui::VKEY_BRIGHTNESS_DOWN
, ui::EF_NONE
);
766 const ui::Accelerator
brightness_up(ui::VKEY_BRIGHTNESS_UP
, ui::EF_NONE
);
768 EXPECT_FALSE(ProcessWithContext(brightness_down
));
769 EXPECT_FALSE(ProcessWithContext(brightness_up
));
770 DummyBrightnessControlDelegate
* delegate
=
771 new DummyBrightnessControlDelegate(true);
772 GetController()->SetBrightnessControlDelegate(
773 scoped_ptr
<BrightnessControlDelegate
>(delegate
).Pass());
774 EXPECT_FALSE(ProcessWithContext(brightness_down
));
775 EXPECT_FALSE(ProcessWithContext(brightness_up
));
777 // Enable internal display.
778 EnableInternalDisplay();
780 DummyBrightnessControlDelegate
* delegate
=
781 new DummyBrightnessControlDelegate(false);
782 GetController()->SetBrightnessControlDelegate(
783 scoped_ptr
<BrightnessControlDelegate
>(delegate
).Pass());
784 EXPECT_EQ(0, delegate
->handle_brightness_down_count());
785 EXPECT_FALSE(ProcessWithContext(brightness_down
));
786 EXPECT_EQ(1, delegate
->handle_brightness_down_count());
787 EXPECT_EQ(brightness_down
, delegate
->last_accelerator());
788 EXPECT_EQ(0, delegate
->handle_brightness_up_count());
789 EXPECT_FALSE(ProcessWithContext(brightness_up
));
790 EXPECT_EQ(1, delegate
->handle_brightness_up_count());
791 EXPECT_EQ(brightness_up
, delegate
->last_accelerator());
794 DummyBrightnessControlDelegate
* delegate
=
795 new DummyBrightnessControlDelegate(true);
796 GetController()->SetBrightnessControlDelegate(
797 scoped_ptr
<BrightnessControlDelegate
>(delegate
).Pass());
798 EXPECT_EQ(0, delegate
->handle_brightness_down_count());
799 EXPECT_TRUE(ProcessWithContext(brightness_down
));
800 EXPECT_EQ(1, delegate
->handle_brightness_down_count());
801 EXPECT_EQ(brightness_down
, delegate
->last_accelerator());
802 EXPECT_EQ(0, delegate
->handle_brightness_up_count());
803 EXPECT_TRUE(ProcessWithContext(brightness_up
));
804 EXPECT_EQ(1, delegate
->handle_brightness_up_count());
805 EXPECT_EQ(brightness_up
, delegate
->last_accelerator());
808 // Keyboard brightness
809 const ui::Accelerator
alt_brightness_down(ui::VKEY_BRIGHTNESS_DOWN
,
811 const ui::Accelerator
alt_brightness_up(ui::VKEY_BRIGHTNESS_UP
,
814 EXPECT_TRUE(ProcessWithContext(alt_brightness_down
));
815 EXPECT_TRUE(ProcessWithContext(alt_brightness_up
));
816 DummyKeyboardBrightnessControlDelegate
* delegate
=
817 new DummyKeyboardBrightnessControlDelegate(false);
818 GetController()->SetKeyboardBrightnessControlDelegate(
819 scoped_ptr
<KeyboardBrightnessControlDelegate
>(delegate
).Pass());
820 EXPECT_EQ(0, delegate
->handle_keyboard_brightness_down_count());
821 EXPECT_FALSE(ProcessWithContext(alt_brightness_down
));
822 EXPECT_EQ(1, delegate
->handle_keyboard_brightness_down_count());
823 EXPECT_EQ(alt_brightness_down
, delegate
->last_accelerator());
824 EXPECT_EQ(0, delegate
->handle_keyboard_brightness_up_count());
825 EXPECT_FALSE(ProcessWithContext(alt_brightness_up
));
826 EXPECT_EQ(1, delegate
->handle_keyboard_brightness_up_count());
827 EXPECT_EQ(alt_brightness_up
, delegate
->last_accelerator());
830 DummyKeyboardBrightnessControlDelegate
* delegate
=
831 new DummyKeyboardBrightnessControlDelegate(true);
832 GetController()->SetKeyboardBrightnessControlDelegate(
833 scoped_ptr
<KeyboardBrightnessControlDelegate
>(delegate
).Pass());
834 EXPECT_EQ(0, delegate
->handle_keyboard_brightness_down_count());
835 EXPECT_TRUE(ProcessWithContext(alt_brightness_down
));
836 EXPECT_EQ(1, delegate
->handle_keyboard_brightness_down_count());
837 EXPECT_EQ(alt_brightness_down
, delegate
->last_accelerator());
838 EXPECT_EQ(0, delegate
->handle_keyboard_brightness_up_count());
839 EXPECT_TRUE(ProcessWithContext(alt_brightness_up
));
840 EXPECT_EQ(1, delegate
->handle_keyboard_brightness_up_count());
841 EXPECT_EQ(alt_brightness_up
, delegate
->last_accelerator());
847 EXPECT_TRUE(ProcessWithContext(
848 ui::Accelerator(ui::VKEY_HOME
, ui::EF_CONTROL_DOWN
)));
849 // ToggleDesktopBackgroundMode
850 EXPECT_TRUE(ProcessWithContext(
851 ui::Accelerator(ui::VKEY_B
, ui::EF_CONTROL_DOWN
| ui::EF_ALT_DOWN
)));
852 #if !defined(OS_LINUX)
853 // ToggleDesktopFullScreen (not implemented yet on Linux)
854 EXPECT_TRUE(ProcessWithContext(
855 ui::Accelerator(ui::VKEY_F11
, ui::EF_CONTROL_DOWN
)));
860 EXPECT_TRUE(ProcessWithContext(
861 ui::Accelerator(ui::VKEY_Q
, ui::EF_SHIFT_DOWN
| ui::EF_CONTROL_DOWN
)));
864 EXPECT_TRUE(ProcessWithContext(
865 ui::Accelerator(ui::VKEY_T
, ui::EF_CONTROL_DOWN
)));
867 // New incognito window
868 EXPECT_TRUE(ProcessWithContext(
869 ui::Accelerator(ui::VKEY_N
, ui::EF_SHIFT_DOWN
| ui::EF_CONTROL_DOWN
)));
872 EXPECT_TRUE(ProcessWithContext(
873 ui::Accelerator(ui::VKEY_N
, ui::EF_CONTROL_DOWN
)));
876 EXPECT_TRUE(ProcessWithContext(
877 ui::Accelerator(ui::VKEY_T
, ui::EF_SHIFT_DOWN
| ui::EF_CONTROL_DOWN
)));
880 EXPECT_TRUE(ProcessWithContext(
881 ui::Accelerator(ui::VKEY_ESCAPE
, ui::EF_SHIFT_DOWN
)));
883 #if defined(OS_CHROMEOS)
884 // Open file manager dialog
885 EXPECT_TRUE(ProcessWithContext(
886 ui::Accelerator(ui::VKEY_O
, ui::EF_CONTROL_DOWN
)));
889 // NOTE: Accelerators that do not work on the lock screen need to be
890 // tested before the sequence below is invoked because it causes a side
891 // effect of locking the screen.
892 EXPECT_TRUE(ProcessWithContext(
893 ui::Accelerator(ui::VKEY_L
, ui::EF_SHIFT_DOWN
| ui::EF_CONTROL_DOWN
)));
897 TEST_F(AcceleratorControllerTest
, GlobalAcceleratorsToggleAppList
) {
898 test::TestShellDelegate
* delegate
=
899 reinterpret_cast<test::TestShellDelegate
*>(
900 ash::Shell::GetInstance()->delegate());
901 EXPECT_FALSE(ash::Shell::GetInstance()->GetAppListTargetVisibility());
903 // The press event should not open the AppList, the release should instead.
904 EXPECT_FALSE(ProcessWithContext(
905 ui::Accelerator(ui::VKEY_LWIN
, ui::EF_NONE
)));
906 EXPECT_TRUE(ProcessWithContext(
907 ReleaseAccelerator(ui::VKEY_LWIN
, ui::EF_NONE
)));
908 EXPECT_TRUE(ash::Shell::GetInstance()->GetAppListTargetVisibility());
910 // When spoken feedback is on, the AppList should not toggle.
911 delegate
->ToggleSpokenFeedback(A11Y_NOTIFICATION_NONE
);
912 EXPECT_FALSE(ProcessWithContext(
913 ui::Accelerator(ui::VKEY_LWIN
, ui::EF_NONE
)));
914 EXPECT_FALSE(ProcessWithContext(
915 ReleaseAccelerator(ui::VKEY_LWIN
, ui::EF_NONE
)));
916 delegate
->ToggleSpokenFeedback(A11Y_NOTIFICATION_NONE
);
917 EXPECT_TRUE(ash::Shell::GetInstance()->GetAppListTargetVisibility());
919 EXPECT_FALSE(ProcessWithContext(
920 ui::Accelerator(ui::VKEY_LWIN
, ui::EF_NONE
)));
921 EXPECT_TRUE(ProcessWithContext(
922 ReleaseAccelerator(ui::VKEY_LWIN
, ui::EF_NONE
)));
923 EXPECT_FALSE(ash::Shell::GetInstance()->GetAppListTargetVisibility());
925 // When spoken feedback is on, the AppList should not toggle.
926 delegate
->ToggleSpokenFeedback(A11Y_NOTIFICATION_NONE
);
927 EXPECT_FALSE(ProcessWithContext(
928 ui::Accelerator(ui::VKEY_LWIN
, ui::EF_NONE
)));
929 EXPECT_FALSE(ProcessWithContext(
930 ReleaseAccelerator(ui::VKEY_LWIN
, ui::EF_NONE
)));
931 delegate
->ToggleSpokenFeedback(A11Y_NOTIFICATION_NONE
);
932 EXPECT_FALSE(ash::Shell::GetInstance()->GetAppListTargetVisibility());
935 TEST_F(AcceleratorControllerTest
, ImeGlobalAccelerators
) {
936 // Test IME shortcuts.
938 const ui::Accelerator
control_space(ui::VKEY_SPACE
, ui::EF_CONTROL_DOWN
);
939 const ui::Accelerator
convert(ui::VKEY_CONVERT
, ui::EF_NONE
);
940 const ui::Accelerator
non_convert(ui::VKEY_NONCONVERT
, ui::EF_NONE
);
941 const ui::Accelerator
wide_half_1(ui::VKEY_DBE_SBCSCHAR
, ui::EF_NONE
);
942 const ui::Accelerator
wide_half_2(ui::VKEY_DBE_DBCSCHAR
, ui::EF_NONE
);
943 const ui::Accelerator
hangul(ui::VKEY_HANGUL
, ui::EF_NONE
);
944 EXPECT_FALSE(ProcessWithContext(control_space
));
945 EXPECT_FALSE(ProcessWithContext(convert
));
946 EXPECT_FALSE(ProcessWithContext(non_convert
));
947 EXPECT_FALSE(ProcessWithContext(wide_half_1
));
948 EXPECT_FALSE(ProcessWithContext(wide_half_2
));
949 EXPECT_FALSE(ProcessWithContext(hangul
));
950 DummyImeControlDelegate
* delegate
= new DummyImeControlDelegate(true);
951 GetController()->SetImeControlDelegate(
952 scoped_ptr
<ImeControlDelegate
>(delegate
).Pass());
953 EXPECT_EQ(0, delegate
->handle_previous_ime_count());
954 EXPECT_TRUE(ProcessWithContext(control_space
));
955 EXPECT_EQ(1, delegate
->handle_previous_ime_count());
956 EXPECT_EQ(0, delegate
->handle_switch_ime_count());
957 EXPECT_TRUE(ProcessWithContext(convert
));
958 EXPECT_EQ(1, delegate
->handle_switch_ime_count());
959 EXPECT_TRUE(ProcessWithContext(non_convert
));
960 EXPECT_EQ(2, delegate
->handle_switch_ime_count());
961 EXPECT_TRUE(ProcessWithContext(wide_half_1
));
962 EXPECT_EQ(3, delegate
->handle_switch_ime_count());
963 EXPECT_TRUE(ProcessWithContext(wide_half_2
));
964 EXPECT_EQ(4, delegate
->handle_switch_ime_count());
965 EXPECT_TRUE(ProcessWithContext(hangul
));
966 EXPECT_EQ(5, delegate
->handle_switch_ime_count());
969 // Test IME shortcuts that are triggered on key release.
971 const ui::Accelerator
shift_alt_press(ui::VKEY_MENU
,
972 ui::EF_SHIFT_DOWN
| ui::EF_ALT_DOWN
);
973 const ReleaseAccelerator
shift_alt(ui::VKEY_MENU
, ui::EF_SHIFT_DOWN
);
974 const ui::Accelerator
alt_shift_press(ui::VKEY_SHIFT
,
975 ui::EF_SHIFT_DOWN
| ui::EF_ALT_DOWN
);
976 const ReleaseAccelerator
alt_shift(ui::VKEY_SHIFT
, ui::EF_ALT_DOWN
);
978 DummyImeControlDelegate
* delegate
= new DummyImeControlDelegate(true);
979 GetController()->SetImeControlDelegate(
980 scoped_ptr
<ImeControlDelegate
>(delegate
).Pass());
981 EXPECT_EQ(0, delegate
->handle_next_ime_count());
982 EXPECT_FALSE(ProcessWithContext(shift_alt_press
));
983 EXPECT_TRUE(ProcessWithContext(shift_alt
));
984 EXPECT_EQ(1, delegate
->handle_next_ime_count());
985 EXPECT_FALSE(ProcessWithContext(alt_shift_press
));
986 EXPECT_TRUE(ProcessWithContext(alt_shift
));
987 EXPECT_EQ(2, delegate
->handle_next_ime_count());
989 // We should NOT switch IME when e.g. Shift+Alt+X is pressed and X is
991 const ui::Accelerator
shift_alt_x_press(
993 ui::EF_SHIFT_DOWN
| ui::EF_ALT_DOWN
);
994 const ReleaseAccelerator
shift_alt_x(ui::VKEY_X
,
995 ui::EF_SHIFT_DOWN
| ui::EF_ALT_DOWN
);
997 EXPECT_FALSE(ProcessWithContext(shift_alt_press
));
998 EXPECT_FALSE(ProcessWithContext(shift_alt_x_press
));
999 EXPECT_FALSE(ProcessWithContext(shift_alt_x
));
1000 EXPECT_FALSE(ProcessWithContext(shift_alt
));
1001 EXPECT_EQ(2, delegate
->handle_next_ime_count());
1003 // But we _should_ if X is either VKEY_RETURN or VKEY_SPACE.
1004 // TODO(nona|mazda): Remove this when crbug.com/139556 in a better way.
1005 const ui::Accelerator
shift_alt_return_press(
1007 ui::EF_SHIFT_DOWN
| ui::EF_ALT_DOWN
);
1008 const ReleaseAccelerator
shift_alt_return(
1010 ui::EF_SHIFT_DOWN
| ui::EF_ALT_DOWN
);
1012 EXPECT_FALSE(ProcessWithContext(shift_alt_press
));
1013 EXPECT_FALSE(ProcessWithContext(shift_alt_return_press
));
1014 EXPECT_FALSE(ProcessWithContext(shift_alt_return
));
1015 EXPECT_TRUE(ProcessWithContext(shift_alt
));
1016 EXPECT_EQ(3, delegate
->handle_next_ime_count());
1018 const ui::Accelerator
shift_alt_space_press(
1020 ui::EF_SHIFT_DOWN
| ui::EF_ALT_DOWN
);
1021 const ReleaseAccelerator
shift_alt_space(
1023 ui::EF_SHIFT_DOWN
| ui::EF_ALT_DOWN
);
1025 EXPECT_FALSE(ProcessWithContext(shift_alt_press
));
1026 EXPECT_FALSE(ProcessWithContext(shift_alt_space_press
));
1027 EXPECT_FALSE(ProcessWithContext(shift_alt_space
));
1028 EXPECT_TRUE(ProcessWithContext(shift_alt
));
1029 EXPECT_EQ(4, delegate
->handle_next_ime_count());
1032 #if defined(OS_CHROMEOS)
1033 // Test IME shortcuts again with unnormalized accelerators (Chrome OS only).
1035 const ui::Accelerator
shift_alt_press(ui::VKEY_MENU
, ui::EF_SHIFT_DOWN
);
1036 const ReleaseAccelerator
shift_alt(ui::VKEY_MENU
, ui::EF_SHIFT_DOWN
);
1037 const ui::Accelerator
alt_shift_press(ui::VKEY_SHIFT
, ui::EF_ALT_DOWN
);
1038 const ReleaseAccelerator
alt_shift(ui::VKEY_SHIFT
, ui::EF_ALT_DOWN
);
1040 DummyImeControlDelegate
* delegate
= new DummyImeControlDelegate(true);
1041 GetController()->SetImeControlDelegate(
1042 scoped_ptr
<ImeControlDelegate
>(delegate
).Pass());
1043 EXPECT_EQ(0, delegate
->handle_next_ime_count());
1044 EXPECT_FALSE(ProcessWithContext(shift_alt_press
));
1045 EXPECT_TRUE(ProcessWithContext(shift_alt
));
1046 EXPECT_EQ(1, delegate
->handle_next_ime_count());
1047 EXPECT_FALSE(ProcessWithContext(alt_shift_press
));
1048 EXPECT_TRUE(ProcessWithContext(alt_shift
));
1049 EXPECT_EQ(2, delegate
->handle_next_ime_count());
1051 // We should NOT switch IME when e.g. Shift+Alt+X is pressed and X is
1053 const ui::Accelerator
shift_alt_x_press(
1055 ui::EF_SHIFT_DOWN
| ui::EF_ALT_DOWN
);
1056 const ReleaseAccelerator
shift_alt_x(ui::VKEY_X
,
1057 ui::EF_SHIFT_DOWN
| ui::EF_ALT_DOWN
);
1059 EXPECT_FALSE(ProcessWithContext(shift_alt_press
));
1060 EXPECT_FALSE(ProcessWithContext(shift_alt_x_press
));
1061 EXPECT_FALSE(ProcessWithContext(shift_alt_x
));
1062 EXPECT_FALSE(ProcessWithContext(shift_alt
));
1063 EXPECT_EQ(2, delegate
->handle_next_ime_count());
1068 // TODO(nona|mazda): Remove this when crbug.com/139556 in a better way.
1069 TEST_F(AcceleratorControllerTest
, ImeGlobalAcceleratorsWorkaround139556
) {
1070 // The workaround for crbug.com/139556 depends on the fact that we don't
1071 // use Shift+Alt+Enter/Space with ET_KEY_PRESSED as an accelerator. Test it.
1072 const ui::Accelerator
shift_alt_return_press(
1074 ui::EF_SHIFT_DOWN
| ui::EF_ALT_DOWN
);
1075 EXPECT_FALSE(ProcessWithContext(shift_alt_return_press
));
1076 const ui::Accelerator
shift_alt_space_press(
1078 ui::EF_SHIFT_DOWN
| ui::EF_ALT_DOWN
);
1079 EXPECT_FALSE(ProcessWithContext(shift_alt_space_press
));
1082 TEST_F(AcceleratorControllerTest
, ReservedAccelerators
) {
1083 // (Shift+)Alt+Tab and Chrome OS top-row keys are reserved.
1084 EXPECT_TRUE(GetController()->IsReservedAccelerator(
1085 ui::Accelerator(ui::VKEY_TAB
, ui::EF_ALT_DOWN
)));
1086 EXPECT_TRUE(GetController()->IsReservedAccelerator(
1087 ui::Accelerator(ui::VKEY_TAB
, ui::EF_SHIFT_DOWN
| ui::EF_ALT_DOWN
)));
1088 #if defined(OS_CHROMEOS)
1089 EXPECT_TRUE(GetController()->IsReservedAccelerator(
1090 ui::Accelerator(ui::VKEY_POWER
, ui::EF_NONE
)));
1092 // Others are not reserved.
1093 EXPECT_FALSE(GetController()->IsReservedAccelerator(
1094 ui::Accelerator(ui::VKEY_PRINT
, ui::EF_NONE
)));
1095 EXPECT_FALSE(GetController()->IsReservedAccelerator(
1096 ui::Accelerator(ui::VKEY_TAB
, ui::EF_NONE
)));
1097 EXPECT_FALSE(GetController()->IsReservedAccelerator(
1098 ui::Accelerator(ui::VKEY_A
, ui::EF_NONE
)));
1101 #if defined(OS_CHROMEOS)
1102 TEST_F(AcceleratorControllerTest
, DisallowedAtModalWindow
) {
1103 std::set
<AcceleratorAction
> allActions
;
1104 for (size_t i
= 0 ; i
< kAcceleratorDataLength
; ++i
)
1105 allActions
.insert(kAcceleratorData
[i
].action
);
1106 std::set
<AcceleratorAction
> actionsAllowedAtModalWindow
;
1107 for (size_t k
= 0 ; k
< kActionsAllowedAtModalWindowLength
; ++k
)
1108 actionsAllowedAtModalWindow
.insert(kActionsAllowedAtModalWindow
[k
]);
1109 for (std::set
<AcceleratorAction
>::const_iterator it
=
1110 actionsAllowedAtModalWindow
.begin();
1111 it
!= actionsAllowedAtModalWindow
.end(); ++it
) {
1112 EXPECT_FALSE(allActions
.find(*it
) == allActions
.end())
1113 << " action from kActionsAllowedAtModalWindow"
1114 << " not found in kAcceleratorData. action: " << *it
;
1116 scoped_ptr
<aura::Window
> window(
1117 CreateTestWindowInShellWithBounds(gfx::Rect(5, 5, 20, 20)));
1118 const ui::Accelerator dummy
;
1119 wm::ActivateWindow(window
.get());
1120 Shell::GetInstance()->SimulateModalWindowOpenForTesting(true);
1121 for (std::set
<AcceleratorAction
>::const_iterator it
= allActions
.begin();
1122 it
!= allActions
.end(); ++it
) {
1123 if (actionsAllowedAtModalWindow
.find(*it
) ==
1124 actionsAllowedAtModalWindow
.end()) {
1125 EXPECT_TRUE(GetController()->PerformAction(*it
, dummy
))
1126 << " for action (disallowed at modal window): " << *it
;
1129 // Testing of top row (F5-F10) accelerators that should still work
1130 // when a modal window is open
1134 EXPECT_TRUE(ProcessWithContext(
1135 ui::Accelerator(ui::VKEY_MEDIA_LAUNCH_APP1
, ui::EF_CONTROL_DOWN
)));
1136 EXPECT_TRUE(ProcessWithContext(
1137 ui::Accelerator(ui::VKEY_PRINT
, ui::EF_NONE
)));
1138 EXPECT_TRUE(ProcessWithContext(
1139 ui::Accelerator(ui::VKEY_MEDIA_LAUNCH_APP1
,
1140 ui::EF_SHIFT_DOWN
| ui::EF_CONTROL_DOWN
)));
1141 DummyScreenshotDelegate
* delegate
= new DummyScreenshotDelegate
;
1142 GetController()->SetScreenshotDelegate(
1143 scoped_ptr
<ScreenshotDelegate
>(delegate
).Pass());
1144 EXPECT_EQ(0, delegate
->handle_take_screenshot_count());
1145 EXPECT_TRUE(ProcessWithContext(
1146 ui::Accelerator(ui::VKEY_MEDIA_LAUNCH_APP1
, ui::EF_CONTROL_DOWN
)));
1147 EXPECT_EQ(1, delegate
->handle_take_screenshot_count());
1148 EXPECT_TRUE(ProcessWithContext(
1149 ui::Accelerator(ui::VKEY_PRINT
, ui::EF_NONE
)));
1150 EXPECT_EQ(2, delegate
->handle_take_screenshot_count());
1151 EXPECT_TRUE(ProcessWithContext(
1152 ui::Accelerator(ui::VKEY_MEDIA_LAUNCH_APP1
,
1153 ui::EF_SHIFT_DOWN
| ui::EF_CONTROL_DOWN
)));
1154 EXPECT_EQ(2, delegate
->handle_take_screenshot_count());
1157 const ui::Accelerator
brightness_down(ui::VKEY_BRIGHTNESS_DOWN
, ui::EF_NONE
);
1158 const ui::Accelerator
brightness_up(ui::VKEY_BRIGHTNESS_UP
, ui::EF_NONE
);
1160 EXPECT_FALSE(ProcessWithContext(brightness_down
));
1161 EXPECT_FALSE(ProcessWithContext(brightness_up
));
1162 DummyBrightnessControlDelegate
* delegate
=
1163 new DummyBrightnessControlDelegate(true);
1164 GetController()->SetBrightnessControlDelegate(
1165 scoped_ptr
<BrightnessControlDelegate
>(delegate
).Pass());
1166 EXPECT_FALSE(ProcessWithContext(brightness_down
));
1167 EXPECT_FALSE(ProcessWithContext(brightness_up
));
1169 EnableInternalDisplay();
1171 EXPECT_FALSE(ProcessWithContext(brightness_down
));
1172 EXPECT_FALSE(ProcessWithContext(brightness_up
));
1173 DummyBrightnessControlDelegate
* delegate
=
1174 new DummyBrightnessControlDelegate(false);
1175 GetController()->SetBrightnessControlDelegate(
1176 scoped_ptr
<BrightnessControlDelegate
>(delegate
).Pass());
1177 EXPECT_EQ(0, delegate
->handle_brightness_down_count());
1178 EXPECT_FALSE(ProcessWithContext(brightness_down
));
1179 EXPECT_EQ(1, delegate
->handle_brightness_down_count());
1180 EXPECT_EQ(brightness_down
, delegate
->last_accelerator());
1181 EXPECT_EQ(0, delegate
->handle_brightness_up_count());
1182 EXPECT_FALSE(ProcessWithContext(brightness_up
));
1183 EXPECT_EQ(1, delegate
->handle_brightness_up_count());
1184 EXPECT_EQ(brightness_up
, delegate
->last_accelerator());
1187 DummyBrightnessControlDelegate
* delegate
=
1188 new DummyBrightnessControlDelegate(true);
1189 GetController()->SetBrightnessControlDelegate(
1190 scoped_ptr
<BrightnessControlDelegate
>(delegate
).Pass());
1191 EXPECT_EQ(0, delegate
->handle_brightness_down_count());
1192 EXPECT_TRUE(ProcessWithContext(brightness_down
));
1193 EXPECT_EQ(1, delegate
->handle_brightness_down_count());
1194 EXPECT_EQ(brightness_down
, delegate
->last_accelerator());
1195 EXPECT_EQ(0, delegate
->handle_brightness_up_count());
1196 EXPECT_TRUE(ProcessWithContext(brightness_up
));
1197 EXPECT_EQ(1, delegate
->handle_brightness_up_count());
1198 EXPECT_EQ(brightness_up
, delegate
->last_accelerator());
1201 const ui::Accelerator
volume_mute(ui::VKEY_VOLUME_MUTE
, ui::EF_NONE
);
1202 const ui::Accelerator
volume_down(ui::VKEY_VOLUME_DOWN
, ui::EF_NONE
);
1203 const ui::Accelerator
volume_up(ui::VKEY_VOLUME_UP
, ui::EF_NONE
);
1205 EXPECT_TRUE(ProcessWithContext(volume_mute
));
1206 EXPECT_TRUE(ProcessWithContext(volume_down
));
1207 EXPECT_TRUE(ProcessWithContext(volume_up
));
1208 DummyVolumeControlDelegate
* delegate
=
1209 new DummyVolumeControlDelegate(false);
1210 ash::Shell::GetInstance()->system_tray_delegate()->SetVolumeControlDelegate(
1211 scoped_ptr
<VolumeControlDelegate
>(delegate
).Pass());
1212 EXPECT_EQ(0, delegate
->handle_volume_mute_count());
1213 EXPECT_FALSE(ProcessWithContext(volume_mute
));
1214 EXPECT_EQ(1, delegate
->handle_volume_mute_count());
1215 EXPECT_EQ(volume_mute
, delegate
->last_accelerator());
1216 EXPECT_EQ(0, delegate
->handle_volume_down_count());
1217 EXPECT_FALSE(ProcessWithContext(volume_down
));
1218 EXPECT_EQ(1, delegate
->handle_volume_down_count());
1219 EXPECT_EQ(volume_down
, delegate
->last_accelerator());
1220 EXPECT_EQ(0, delegate
->handle_volume_up_count());
1221 EXPECT_FALSE(ProcessWithContext(volume_up
));
1222 EXPECT_EQ(1, delegate
->handle_volume_up_count());
1223 EXPECT_EQ(volume_up
, delegate
->last_accelerator());
1226 DummyVolumeControlDelegate
* delegate
= new DummyVolumeControlDelegate(true);
1227 ash::Shell::GetInstance()->system_tray_delegate()->SetVolumeControlDelegate(
1228 scoped_ptr
<VolumeControlDelegate
>(delegate
).Pass());
1229 EXPECT_EQ(0, delegate
->handle_volume_mute_count());
1230 EXPECT_TRUE(ProcessWithContext(volume_mute
));
1231 EXPECT_EQ(1, delegate
->handle_volume_mute_count());
1232 EXPECT_EQ(volume_mute
, delegate
->last_accelerator());
1233 EXPECT_EQ(0, delegate
->handle_volume_down_count());
1234 EXPECT_TRUE(ProcessWithContext(volume_down
));
1235 EXPECT_EQ(1, delegate
->handle_volume_down_count());
1236 EXPECT_EQ(volume_down
, delegate
->last_accelerator());
1237 EXPECT_EQ(0, delegate
->handle_volume_up_count());
1238 EXPECT_TRUE(ProcessWithContext(volume_up
));
1239 EXPECT_EQ(1, delegate
->handle_volume_up_count());
1240 EXPECT_EQ(volume_up
, delegate
->last_accelerator());