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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/accelerators/magnifier_key_scroller.h"
#include "ash/magnifier/magnification_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/events/event.h"
#include "ui/events/test/event_generator.h"
namespace ash {
namespace {
class KeyEventDelegate : public aura::test::TestWindowDelegate {
public:
KeyEventDelegate() {}
~KeyEventDelegate() override {}
// ui::EventHandler overrides:
void OnKeyEvent(ui::KeyEvent* event) override {
key_event.reset(new ui::KeyEvent(
event->type(), event->key_code(), event->flags()));
}
const ui::KeyEvent* event() const { return key_event.get(); }
void reset() { key_event.reset(); }
private:
scoped_ptr<ui::KeyEvent> key_event;
DISALLOW_COPY_AND_ASSIGN(KeyEventDelegate);
};
} // namespace
typedef ash::test::AshTestBase MagnifierKeyScrollerTest;
TEST_F(MagnifierKeyScrollerTest, Basic) {
KeyEventDelegate delegate;
scoped_ptr<aura::Window> window(CreateTestWindowInShellWithDelegate(
&delegate,
0,
gfx::Rect(10, 10, 100, 100)));
wm::ActivateWindow(window.get());
MagnifierKeyScroller::ScopedEnablerForTest scoped;
Shell* shell = Shell::GetInstance();
MagnificationController* controller = shell->magnification_controller();
controller->SetEnabled(true);
EXPECT_EQ("200,150", controller->GetWindowPosition().ToString());
ui::test::EventGenerator& generator = GetEventGenerator();
// Click and Release generates the press event upon release.
generator.PressKey(ui::VKEY_DOWN, ui::EF_SHIFT_DOWN);
EXPECT_EQ("200,150", controller->GetWindowPosition().ToString());
EXPECT_FALSE(delegate.event());
generator.ReleaseKey(ui::VKEY_DOWN, 0);
EXPECT_EQ("200,150", controller->GetWindowPosition().ToString());
RunAllPendingInMessageLoop();
ASSERT_TRUE(delegate.event());
EXPECT_EQ(ui::ET_KEY_PRESSED, delegate.event()->type());
delegate.reset();
// Click and hold scrolls the magnifier screen.
generator.PressKey(ui::VKEY_DOWN, ui::EF_SHIFT_DOWN);
EXPECT_EQ("200,150", controller->GetWindowPosition().ToString());
EXPECT_FALSE(delegate.event());
generator.PressKey(ui::VKEY_DOWN, ui::EF_SHIFT_DOWN);
EXPECT_EQ("200,300", controller->GetWindowPosition().ToString());
EXPECT_FALSE(delegate.event());
generator.ReleaseKey(ui::VKEY_DOWN, 0);
EXPECT_EQ("200,300", controller->GetWindowPosition().ToString());
EXPECT_FALSE(delegate.event());
// Events are passed normally when the magnifier is off.
controller->SetEnabled(false);
generator.PressKey(ui::VKEY_DOWN, ui::EF_SHIFT_DOWN);
ASSERT_TRUE(delegate.event());
EXPECT_EQ(ui::ET_KEY_PRESSED, delegate.event()->type());
delegate.reset();
generator.ReleaseKey(ui::VKEY_DOWN, 0);
ASSERT_TRUE(delegate.event());
EXPECT_EQ(ui::ET_KEY_RELEASED, delegate.event()->type());
delegate.reset();
generator.PressKey(ui::VKEY_DOWN, ui::EF_SHIFT_DOWN);
ASSERT_TRUE(delegate.event());
EXPECT_EQ(ui::ET_KEY_PRESSED, delegate.event()->type());
delegate.reset();
generator.PressKey(ui::VKEY_DOWN, ui::EF_SHIFT_DOWN);
ASSERT_TRUE(delegate.event());
EXPECT_EQ(ui::ET_KEY_PRESSED, delegate.event()->type());
delegate.reset();
generator.ReleaseKey(ui::VKEY_DOWN, 0);
ASSERT_TRUE(delegate.event());
EXPECT_EQ(ui::ET_KEY_RELEASED, delegate.event()->type());
delegate.reset();
}
} // namespace ash
|