2
* Copyright © 2015 Canonical Ltd.
4
* This program is free software: you can redistribute it and/or modify it
5
* under the terms of the GNU General Public License version 3,
6
* as published by the Free Software Foundation.
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU General Public License for more details.
13
* You should have received a copy of the GNU General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16
* Authored by: Andreas Pokorny <andreas.pokorny@canonical.com>
19
#include "InputDispatcher.h"
20
#include "InputApplication.h"
21
#include "InputWindow.h"
22
#include "InputWindow.h"
24
#include "mir/input/android/android_input_lexicon.h"
25
#include "mir/events/event_private.h"
26
#include "mir/report/legacy_input_report.h"
27
#include "src/server/report/null_report_factory.h"
28
#include "src/server/input/android/event_filter_dispatcher_policy.h"
30
#include "mir_test_doubles/stub_input_enumerator.h"
31
#include "mir_test_doubles/mock_event_filter.h"
32
#include "mir_test_doubles/null_logger.h"
33
#include "mir_test/fake_shared.h"
34
#include "mir_test/event_matchers.h"
36
#include <gtest/gtest.h>
37
#include <gmock/gmock.h>
39
#include <linux/input.h>
41
namespace mt = mir::test;
42
namespace mtd = mt::doubles;
43
namespace mia = mir::input::android;
44
using namespace std::literals;
48
struct MockInputDispatcherPolicy : mia::EventFilterDispatcherPolicy
50
using mia::EventFilterDispatcherPolicy::EventFilterDispatcherPolicy;
51
MOCK_METHOD1(handle,void(MirEvent const& event));
52
std::chrono::nanoseconds interceptKeyBeforeDispatching(
53
const android::sp<android::InputWindowHandle>&,
54
const android::KeyEvent* keyEvent, uint32_t)
57
mia::Lexicon::translate(keyEvent, mir_ev);
64
struct InputDispatcher : testing::Test
66
mtd::StubInputEnumerator enumerator;
67
testing::NiceMock<mtd::MockEventFilter> filter;
68
testing::NiceMock<MockInputDispatcherPolicy> filter_policy{mt::fake_shared(filter), true};
69
android::InputDispatcher dispatcher{mt::fake_shared(filter_policy), mir::report::null_input_report(), mt::fake_shared(enumerator)};
70
mtd::NullLogger logger;
73
mir::report::legacy_input::initialize(mt::fake_shared(logger));
76
android::NotifyKeyArgs create_key_event(int32_t key_code, int32_t scan_code, int32_t action = AKEY_EVENT_ACTION_DOWN)
78
static auto time = 0ns;
81
uint32_t source = AINPUT_SOURCE_KEYBOARD;
82
uint32_t policy_flag = 0;
84
int32_t meta_state = 0;
87
return android::NotifyKeyArgs{time, deviceid, source, policy_flag, action, flag, key_code, scan_code, meta_state, down_time};
93
TEST_F(InputDispatcher, forwards_multiple_downs)
95
using namespace ::testing;
97
EXPECT_CALL(filter_policy, handle(AllOf(mt::KeyDownEvent(), mt::KeyOfScanCode(KEY_RIGHTSHIFT))));
98
EXPECT_CALL(filter_policy, handle(AllOf(mt::KeyDownEvent(), mt::KeyOfScanCode(KEY_M))));
99
auto first_key_event = create_key_event(0, KEY_RIGHTSHIFT);
100
auto second_key_event = create_key_event(0, KEY_M);
102
dispatcher.notifyKey(&first_key_event);
103
dispatcher.notifyKey(&second_key_event);
105
dispatcher.dispatchOnce();
106
dispatcher.dispatchOnce();
107
dispatcher.dispatchOnce();
110
TEST_F(InputDispatcher, detects_multiple_down_of_same_key)
112
using namespace ::testing;
114
EXPECT_CALL(filter_policy, handle(AllOf(mt::KeyDownEvent(), mt::KeyOfScanCode(KEY_M))));
115
EXPECT_CALL(filter_policy, handle(AllOf(mt::KeyRepeatEvent(), mt::KeyOfScanCode(KEY_M))));
116
auto first_key_event = create_key_event(0, KEY_M);
117
auto second_key_event = create_key_event(0, KEY_M);
119
dispatcher.notifyKey(&first_key_event);
120
dispatcher.notifyKey(&second_key_event);
122
dispatcher.dispatchOnce();
123
dispatcher.dispatchOnce();
124
dispatcher.dispatchOnce();