1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
ash / accelerators / spoken_feedback_toggler_unittest.cc [blame]
// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/accelerators/spoken_feedback_toggler.h"
#include "ash/accessibility/accessibility_controller.h"
#include "ash/shell.h"
#include "ash/test/ash_test_base.h"
#include "ash/wm/window_util.h"
#include "ui/aura/test/test_window_delegate.h"
#include "ui/aura/window.h"
#include "ui/events/test/event_generator.h"
namespace ash {
using SpokenFeedbackTogglerTest = AshTestBase;
TEST_F(SpokenFeedbackTogglerTest, Basic) {
SpokenFeedbackToggler::ScopedEnablerForTest scoped;
AccessibilityController* controller =
Shell::Get()->accessibility_controller();
ui::test::EventGenerator* generator = GetEventGenerator();
EXPECT_FALSE(controller->spoken_feedback().enabled());
generator->PressKey(ui::VKEY_F6, ui::EF_SHIFT_DOWN);
EXPECT_FALSE(controller->spoken_feedback().enabled());
generator->ReleaseKey(ui::VKEY_F6, 0);
EXPECT_FALSE(controller->spoken_feedback().enabled());
// Click and hold toggles the spoken feedback.
generator->PressKey(ui::VKEY_F6, ui::EF_SHIFT_DOWN);
EXPECT_FALSE(controller->spoken_feedback().enabled());
generator->PressKey(ui::VKEY_F6, ui::EF_SHIFT_DOWN);
EXPECT_TRUE(controller->spoken_feedback().enabled());
generator->PressKey(ui::VKEY_F6, ui::EF_SHIFT_DOWN);
EXPECT_TRUE(controller->spoken_feedback().enabled());
generator->ReleaseKey(ui::VKEY_F6, 0);
EXPECT_TRUE(controller->spoken_feedback().enabled());
// toggle again
generator->PressKey(ui::VKEY_F6, ui::EF_SHIFT_DOWN);
EXPECT_TRUE(controller->spoken_feedback().enabled());
generator->PressKey(ui::VKEY_F6, ui::EF_SHIFT_DOWN);
EXPECT_FALSE(controller->spoken_feedback().enabled());
generator->PressKey(ui::VKEY_F6, ui::EF_SHIFT_DOWN);
EXPECT_FALSE(controller->spoken_feedback().enabled());
generator->ReleaseKey(ui::VKEY_F6, 0);
EXPECT_FALSE(controller->spoken_feedback().enabled());
}
TEST_F(SpokenFeedbackTogglerTest, PassThroughEvents) {
SpokenFeedbackToggler::ScopedEnablerForTest scoped;
aura::test::EventCountDelegate delegate;
std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithDelegate(
&delegate, 0, gfx::Rect(0, 0, 100, 100)));
window->Focus();
ui::test::EventGenerator* generator = GetEventGenerator();
// None hotkey events.
generator->PressKey(ui::VKEY_A, 0);
generator->ReleaseKey(ui::VKEY_F6, 0);
EXPECT_EQ("1 1", delegate.GetKeyCountsAndReset());
// Single hotkey press and release.
generator->PressKey(ui::VKEY_F6, ui::EF_SHIFT_DOWN);
generator->ReleaseKey(ui::VKEY_F6, 0);
EXPECT_EQ("1 1", delegate.GetKeyCountsAndReset());
// Hotkey press and hold.
generator->PressKey(ui::VKEY_F6, ui::EF_SHIFT_DOWN);
generator->PressKey(ui::VKEY_F6, ui::EF_SHIFT_DOWN);
generator->PressKey(ui::VKEY_F6, ui::EF_SHIFT_DOWN);
generator->ReleaseKey(ui::VKEY_F6, 0);
EXPECT_EQ("3 1", delegate.GetKeyCountsAndReset());
}
} // namespace ash