1 // Copyright 2014 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/spoken_feedback_toggler.h"
6 #include "ash/accessibility_delegate.h"
8 #include "ash/test/ash_test_base.h"
9 #include "ash/wm/window_util.h"
10 #include "ui/aura/test/test_window_delegate.h"
11 #include "ui/events/test/event_generator.h"
15 typedef ash::test::AshTestBase SpokenFeedbackTogglerTest
;
17 TEST_F(SpokenFeedbackTogglerTest
, Basic
) {
18 SpokenFeedbackToggler::ScopedEnablerForTest scoped
;
19 Shell
* shell
= Shell::GetInstance();
20 AccessibilityDelegate
* delegate
= shell
->accessibility_delegate();
21 ui::test::EventGenerator
& generator
= GetEventGenerator();
22 EXPECT_FALSE(delegate
->IsSpokenFeedbackEnabled());
24 generator
.PressKey(ui::VKEY_F6
, ui::EF_SHIFT_DOWN
);
25 EXPECT_FALSE(delegate
->IsSpokenFeedbackEnabled());
26 generator
.ReleaseKey(ui::VKEY_F6
, 0);
27 EXPECT_FALSE(delegate
->IsSpokenFeedbackEnabled());
29 // Click and hold toggles the spoken feedback.
30 generator
.PressKey(ui::VKEY_F6
, ui::EF_SHIFT_DOWN
);
31 EXPECT_FALSE(delegate
->IsSpokenFeedbackEnabled());
32 generator
.PressKey(ui::VKEY_F6
, ui::EF_SHIFT_DOWN
);
33 EXPECT_TRUE(delegate
->IsSpokenFeedbackEnabled());
34 generator
.PressKey(ui::VKEY_F6
, ui::EF_SHIFT_DOWN
);
35 EXPECT_TRUE(delegate
->IsSpokenFeedbackEnabled());
36 generator
.ReleaseKey(ui::VKEY_F6
, 0);
37 EXPECT_TRUE(delegate
->IsSpokenFeedbackEnabled());
40 generator
.PressKey(ui::VKEY_F6
, ui::EF_SHIFT_DOWN
);
41 EXPECT_TRUE(delegate
->IsSpokenFeedbackEnabled());
42 generator
.PressKey(ui::VKEY_F6
, ui::EF_SHIFT_DOWN
);
43 EXPECT_FALSE(delegate
->IsSpokenFeedbackEnabled());
44 generator
.PressKey(ui::VKEY_F6
, ui::EF_SHIFT_DOWN
);
45 EXPECT_FALSE(delegate
->IsSpokenFeedbackEnabled());
46 generator
.ReleaseKey(ui::VKEY_F6
, 0);
47 EXPECT_FALSE(delegate
->IsSpokenFeedbackEnabled());
50 TEST_F(SpokenFeedbackTogglerTest
, PassThroughEvents
) {
51 SpokenFeedbackToggler::ScopedEnablerForTest scoped
;
53 aura::test::EventCountDelegate delegate
;
54 scoped_ptr
<aura::Window
> window(CreateTestWindowInShellWithDelegate(
55 &delegate
, 0, gfx::Rect(0, 0, 100, 100)));
58 ui::test::EventGenerator
& generator
= GetEventGenerator();
60 // None hotkey events.
61 generator
.PressKey(ui::VKEY_A
, 0);
62 generator
.ReleaseKey(ui::VKEY_F6
, 0);
63 EXPECT_EQ("1 1", delegate
.GetKeyCountsAndReset());
65 // Single hotkey press and release.
66 generator
.PressKey(ui::VKEY_F6
, ui::EF_SHIFT_DOWN
);
67 generator
.ReleaseKey(ui::VKEY_F6
, 0);
68 EXPECT_EQ("1 1", delegate
.GetKeyCountsAndReset());
70 // Hotkey press and hold.
71 generator
.PressKey(ui::VKEY_F6
, ui::EF_SHIFT_DOWN
);
72 generator
.PressKey(ui::VKEY_F6
, ui::EF_SHIFT_DOWN
);
73 generator
.PressKey(ui::VKEY_F6
, ui::EF_SHIFT_DOWN
);
74 generator
.ReleaseKey(ui::VKEY_F6
, 0);
75 EXPECT_EQ("3 1", delegate
.GetKeyCountsAndReset());