blob: 200033552115234262f56b784501ad4fb4cb42a3 [file] [log] [blame]
Jeff Brown5912f952013-07-01 19:10:31 -07001/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "TestHelpers.h"
18
chaviw09c8d2d2020-08-24 15:48:26 -070019#include <attestation/HmacKeyManager.h>
Jeff Brown5912f952013-07-01 19:10:31 -070020#include <gtest/gtest.h>
chaviw3277faf2021-05-19 16:45:23 -050021#include <gui/constants.h>
Jeff Brown5912f952013-07-01 19:10:31 -070022#include <input/InputTransport.h>
Jeff Brown5912f952013-07-01 19:10:31 -070023
Siarhei Vishniakoueedd0fc2021-03-12 09:50:36 +000024using android::base::Result;
25
Jeff Brown5912f952013-07-01 19:10:31 -070026namespace android {
27
Siarhei Vishniakou6252af72023-09-20 09:00:38 -070028namespace {
29
30static constexpr float EPSILON = MotionEvent::ROUNDING_PRECISION;
31static constexpr int32_t POINTER_1_DOWN =
32 AMOTION_EVENT_ACTION_POINTER_DOWN | (1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT);
33static constexpr int32_t POINTER_2_DOWN =
34 AMOTION_EVENT_ACTION_POINTER_DOWN | (2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT);
35
36struct Pointer {
37 int32_t id;
38 float x;
39 float y;
40 bool isResampled = false;
41};
42
Egor Paskoa0d32af2023-12-14 17:45:41 +010043// A collection of arguments to be sent as publishMotionEvent(). The saved members of this struct
44// allow to check the expectations against the event acquired from the InputReceiver. To help
45// simplify expectation checking it carries members not present in MotionEvent, like |rawXScale|.
46struct PublishMotionArgs {
47 const int32_t action;
48 const nsecs_t downTime;
49 const uint32_t seq;
50 const int32_t eventId;
51 const int32_t deviceId = 1;
52 const uint32_t source = AINPUT_SOURCE_TOUCHSCREEN;
53 const int32_t displayId = ADISPLAY_ID_DEFAULT;
54 const int32_t actionButton = 0;
55 const int32_t edgeFlags = AMOTION_EVENT_EDGE_FLAG_TOP;
56 const int32_t metaState = AMETA_ALT_LEFT_ON | AMETA_ALT_ON;
57 const int32_t buttonState = AMOTION_EVENT_BUTTON_PRIMARY;
58 const MotionClassification classification = MotionClassification::AMBIGUOUS_GESTURE;
59 const float xScale = 2;
60 const float yScale = 3;
61 const float xOffset = -10;
62 const float yOffset = -20;
63 const float rawXScale = 4;
64 const float rawYScale = -5;
65 const float rawXOffset = -11;
66 const float rawYOffset = 42;
67 const float xPrecision = 0.25;
68 const float yPrecision = 0.5;
69 const float xCursorPosition = 1.3;
70 const float yCursorPosition = 50.6;
71 std::array<uint8_t, 32> hmac;
72 int32_t flags;
73 ui::Transform transform;
74 ui::Transform rawTransform;
75 const nsecs_t eventTime;
76 size_t pointerCount;
77 std::vector<PointerProperties> pointerProperties;
78 std::vector<PointerCoords> pointerCoords;
79
80 PublishMotionArgs(int32_t action, nsecs_t downTime, const std::vector<Pointer>& pointers,
81 const uint32_t seq);
82};
83
84PublishMotionArgs::PublishMotionArgs(int32_t inAction, nsecs_t inDownTime,
85 const std::vector<Pointer>& pointers, const uint32_t inSeq)
86 : action(inAction),
87 downTime(inDownTime),
88 seq(inSeq),
89 eventId(InputEvent::nextId()),
90 eventTime(systemTime(SYSTEM_TIME_MONOTONIC)) {
91 hmac = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
92 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31};
93
94 flags = AMOTION_EVENT_FLAG_WINDOW_IS_OBSCURED;
95 if (action == AMOTION_EVENT_ACTION_CANCEL) {
96 flags |= AMOTION_EVENT_FLAG_CANCELED;
97 }
98 pointerCount = pointers.size();
99 for (size_t i = 0; i < pointerCount; i++) {
100 pointerProperties.push_back({});
101 pointerProperties[i].clear();
102 pointerProperties[i].id = pointers[i].id;
103 pointerProperties[i].toolType = ToolType::FINGER;
104
105 pointerCoords.push_back({});
106 pointerCoords[i].clear();
107 pointerCoords[i].isResampled = pointers[i].isResampled;
108 pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_X, pointers[i].x);
109 pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_Y, pointers[i].y);
110 pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_PRESSURE, 0.5 * i);
111 pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_SIZE, 0.7 * i);
112 pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_TOUCH_MAJOR, 1.5 * i);
113 pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_TOUCH_MINOR, 1.7 * i);
114 pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_TOOL_MAJOR, 2.5 * i);
115 pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_TOOL_MAJOR, 2.7 * i);
116 pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_ORIENTATION, 3.5 * i);
117 }
118 transform.set({xScale, 0, xOffset, 0, yScale, yOffset, 0, 0, 1});
119 rawTransform.set({rawXScale, 0, rawXOffset, 0, rawYScale, rawYOffset, 0, 0, 1});
120}
121
122// Checks expectations against |motionEvent| acquired from an InputConsumer. Floating point
123// comparisons limit precision to EPSILON.
124void verifyArgsEqualToEvent(const PublishMotionArgs& args, const MotionEvent& motionEvent) {
125 EXPECT_EQ(args.eventId, motionEvent.getId());
126 EXPECT_EQ(args.deviceId, motionEvent.getDeviceId());
127 EXPECT_EQ(args.source, motionEvent.getSource());
128 EXPECT_EQ(args.displayId, motionEvent.getDisplayId());
129 EXPECT_EQ(args.hmac, motionEvent.getHmac());
130 EXPECT_EQ(args.action, motionEvent.getAction());
131 EXPECT_EQ(args.downTime, motionEvent.getDownTime());
132 EXPECT_EQ(args.flags, motionEvent.getFlags());
133 EXPECT_EQ(args.edgeFlags, motionEvent.getEdgeFlags());
134 EXPECT_EQ(args.metaState, motionEvent.getMetaState());
135 EXPECT_EQ(args.buttonState, motionEvent.getButtonState());
136 EXPECT_EQ(args.classification, motionEvent.getClassification());
137 EXPECT_EQ(args.transform, motionEvent.getTransform());
138 EXPECT_EQ(args.xOffset, motionEvent.getXOffset());
139 EXPECT_EQ(args.yOffset, motionEvent.getYOffset());
140 EXPECT_EQ(args.xPrecision, motionEvent.getXPrecision());
141 EXPECT_EQ(args.yPrecision, motionEvent.getYPrecision());
142 EXPECT_NEAR(args.xCursorPosition, motionEvent.getRawXCursorPosition(), EPSILON);
143 EXPECT_NEAR(args.yCursorPosition, motionEvent.getRawYCursorPosition(), EPSILON);
144 EXPECT_NEAR(args.xCursorPosition * args.xScale + args.xOffset, motionEvent.getXCursorPosition(),
145 EPSILON);
146 EXPECT_NEAR(args.yCursorPosition * args.yScale + args.yOffset, motionEvent.getYCursorPosition(),
147 EPSILON);
148 EXPECT_EQ(args.rawTransform, motionEvent.getRawTransform());
149 EXPECT_EQ(args.eventTime, motionEvent.getEventTime());
150 EXPECT_EQ(args.pointerCount, motionEvent.getPointerCount());
151 EXPECT_EQ(0U, motionEvent.getHistorySize());
152
153 for (size_t i = 0; i < args.pointerCount; i++) {
154 SCOPED_TRACE(i);
155 EXPECT_EQ(args.pointerProperties[i].id, motionEvent.getPointerId(i));
156 EXPECT_EQ(args.pointerProperties[i].toolType, motionEvent.getToolType(i));
157
158 const auto& pc = args.pointerCoords[i];
159 EXPECT_EQ(pc, motionEvent.getSamplePointerCoords()[i]);
160
161 EXPECT_NEAR(pc.getX() * args.rawXScale + args.rawXOffset, motionEvent.getRawX(i), EPSILON);
162 EXPECT_NEAR(pc.getY() * args.rawYScale + args.rawYOffset, motionEvent.getRawY(i), EPSILON);
163 EXPECT_NEAR(pc.getX() * args.xScale + args.xOffset, motionEvent.getX(i), EPSILON);
164 EXPECT_NEAR(pc.getY() * args.yScale + args.yOffset, motionEvent.getY(i), EPSILON);
165 EXPECT_EQ(pc.getAxisValue(AMOTION_EVENT_AXIS_PRESSURE), motionEvent.getPressure(i));
166 EXPECT_EQ(pc.getAxisValue(AMOTION_EVENT_AXIS_SIZE), motionEvent.getSize(i));
167 EXPECT_EQ(pc.getAxisValue(AMOTION_EVENT_AXIS_TOUCH_MAJOR), motionEvent.getTouchMajor(i));
168 EXPECT_EQ(pc.getAxisValue(AMOTION_EVENT_AXIS_TOUCH_MINOR), motionEvent.getTouchMinor(i));
169 EXPECT_EQ(pc.getAxisValue(AMOTION_EVENT_AXIS_TOOL_MAJOR), motionEvent.getToolMajor(i));
170 EXPECT_EQ(pc.getAxisValue(AMOTION_EVENT_AXIS_TOOL_MINOR), motionEvent.getToolMinor(i));
171
172 // Calculate the orientation after scaling, keeping in mind that an orientation of 0 is
173 // "up", and the positive y direction is "down".
174 const float unscaledOrientation = pc.getAxisValue(AMOTION_EVENT_AXIS_ORIENTATION);
175 const float x = sinf(unscaledOrientation) * args.xScale;
176 const float y = -cosf(unscaledOrientation) * args.yScale;
177 EXPECT_EQ(atan2f(x, -y), motionEvent.getOrientation(i));
178 }
179}
180
181void publishMotionEvent(InputPublisher& publisher, const PublishMotionArgs& a) {
182 status_t status =
183 publisher.publishMotionEvent(a.seq, a.eventId, a.deviceId, a.source, a.displayId,
184 a.hmac, a.action, a.actionButton, a.flags, a.edgeFlags,
185 a.metaState, a.buttonState, a.classification, a.transform,
186 a.xPrecision, a.yPrecision, a.xCursorPosition,
187 a.yCursorPosition, a.rawTransform, a.downTime, a.eventTime,
188 a.pointerCount, a.pointerProperties.data(),
189 a.pointerCoords.data());
190 ASSERT_EQ(OK, status) << "publisher publishMotionEvent should return OK";
191}
192
193void sendAndVerifyFinishedSignal(InputConsumer& consumer, InputPublisher& publisher, uint32_t seq,
194 nsecs_t publishTime) {
195 status_t status = consumer.sendFinishedSignal(seq, false);
196 ASSERT_EQ(OK, status) << "consumer sendFinishedSignal should return OK";
197 Result<InputPublisher::ConsumerResponse> result = publisher.receiveConsumerResponse();
198 ASSERT_TRUE(result.ok()) << "receiveConsumerResponse should return OK";
199 ASSERT_TRUE(std::holds_alternative<InputPublisher::Finished>(*result));
200 const InputPublisher::Finished& finish = std::get<InputPublisher::Finished>(*result);
201 ASSERT_EQ(seq, finish.seq)
202 << "receiveConsumerResponse should have returned the original sequence number";
203 ASSERT_FALSE(finish.handled)
204 << "receiveConsumerResponse should have set handled to consumer's reply";
205 ASSERT_GE(finish.consumeTime, publishTime)
206 << "finished signal's consume time should be greater than publish time";
207}
208
209void waitUntilInputAvailable(const InputConsumer& inputConsumer) {
210 bool hasInput;
211 do {
212 // The probablyHasInput() can return false positive under rare circumstances uncontrollable
213 // by the tests. Re-request the availability in this case. Returning |false| for a long
214 // time is not intended, and would cause a test timeout.
215 hasInput = inputConsumer.probablyHasInput();
216 } while (!hasInput);
217}
218
Siarhei Vishniakou6252af72023-09-20 09:00:38 -0700219} // namespace
Prabir Pradhan00e029d2023-03-09 20:11:09 +0000220
Jeff Brown5912f952013-07-01 19:10:31 -0700221class InputPublisherAndConsumerTest : public testing::Test {
222protected:
Siarhei Vishniakoud2588272020-07-10 11:15:40 -0500223 std::shared_ptr<InputChannel> mServerChannel, mClientChannel;
224 std::unique_ptr<InputPublisher> mPublisher;
225 std::unique_ptr<InputConsumer> mConsumer;
Jeff Brown5912f952013-07-01 19:10:31 -0700226 PreallocatedInputEventFactory mEventFactory;
227
Siarhei Vishniakoud2588272020-07-10 11:15:40 -0500228 void SetUp() override {
229 std::unique_ptr<InputChannel> serverChannel, clientChannel;
Siarhei Vishniakouf93fcf42017-11-22 16:00:14 -0800230 status_t result = InputChannel::openInputChannelPair("channel name",
Jeff Brown5912f952013-07-01 19:10:31 -0700231 serverChannel, clientChannel);
Siarhei Vishniakou54d3e182020-01-15 17:38:38 -0800232 ASSERT_EQ(OK, result);
Siarhei Vishniakoud2588272020-07-10 11:15:40 -0500233 mServerChannel = std::move(serverChannel);
234 mClientChannel = std::move(clientChannel);
Jeff Brown5912f952013-07-01 19:10:31 -0700235
Siarhei Vishniakoud2588272020-07-10 11:15:40 -0500236 mPublisher = std::make_unique<InputPublisher>(mServerChannel);
237 mConsumer = std::make_unique<InputConsumer>(mClientChannel);
Jeff Brown5912f952013-07-01 19:10:31 -0700238 }
239
Siarhei Vishniakou6252af72023-09-20 09:00:38 -0700240 void publishAndConsumeKeyEvent();
241 void publishAndConsumeMotionStream();
Egor Paskoa0d32af2023-12-14 17:45:41 +0100242 void publishAndConsumeMotionDown(nsecs_t downTime);
243 void publishAndConsumeBatchedMotionMove(nsecs_t downTime);
Siarhei Vishniakou6252af72023-09-20 09:00:38 -0700244 void publishAndConsumeFocusEvent();
245 void publishAndConsumeCaptureEvent();
246 void publishAndConsumeDragEvent();
247 void publishAndConsumeTouchModeEvent();
248 void publishAndConsumeMotionEvent(int32_t action, nsecs_t downTime,
249 const std::vector<Pointer>& pointers);
250
251private:
252 // The sequence number to use when publishing the next event
253 uint32_t mSeq = 1;
Jeff Brown5912f952013-07-01 19:10:31 -0700254};
255
256TEST_F(InputPublisherAndConsumerTest, GetChannel_ReturnsTheChannel) {
Siarhei Vishniakoua1188f52020-10-20 20:14:52 -0500257 ASSERT_NE(nullptr, mPublisher->getChannel());
258 ASSERT_NE(nullptr, mConsumer->getChannel());
Siarhei Vishniakoud2588272020-07-10 11:15:40 -0500259 EXPECT_EQ(mServerChannel.get(), mPublisher->getChannel().get());
260 EXPECT_EQ(mClientChannel.get(), mConsumer->getChannel().get());
Siarhei Vishniakoua1188f52020-10-20 20:14:52 -0500261 ASSERT_EQ(mPublisher->getChannel()->getConnectionToken(),
262 mConsumer->getChannel()->getConnectionToken());
Jeff Brown5912f952013-07-01 19:10:31 -0700263}
264
Siarhei Vishniakou6252af72023-09-20 09:00:38 -0700265void InputPublisherAndConsumerTest::publishAndConsumeKeyEvent() {
Jeff Brown5912f952013-07-01 19:10:31 -0700266 status_t status;
267
Siarhei Vishniakou6252af72023-09-20 09:00:38 -0700268 const uint32_t seq = mSeq++;
Garfield Tanff1f1bb2020-01-28 13:24:04 -0800269 int32_t eventId = InputEvent::nextId();
Siarhei Vishniakoua62a8dd2018-06-08 21:17:33 +0100270 constexpr int32_t deviceId = 1;
Siarhei Vishniakou3826d472020-01-27 10:44:40 -0600271 constexpr uint32_t source = AINPUT_SOURCE_KEYBOARD;
Siarhei Vishniakoua62a8dd2018-06-08 21:17:33 +0100272 constexpr int32_t displayId = ADISPLAY_ID_DEFAULT;
Siarhei Vishniakou9c858ac2020-01-23 14:20:11 -0600273 constexpr std::array<uint8_t, 32> hmac = {31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21,
274 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10,
275 9, 8, 7, 6, 5, 4, 3, 2, 1, 0};
Siarhei Vishniakoua62a8dd2018-06-08 21:17:33 +0100276 constexpr int32_t action = AKEY_EVENT_ACTION_DOWN;
277 constexpr int32_t flags = AKEY_EVENT_FLAG_FROM_SYSTEM;
278 constexpr int32_t keyCode = AKEYCODE_ENTER;
279 constexpr int32_t scanCode = 13;
280 constexpr int32_t metaState = AMETA_ALT_LEFT_ON | AMETA_ALT_ON;
281 constexpr int32_t repeatCount = 1;
282 constexpr nsecs_t downTime = 3;
283 constexpr nsecs_t eventTime = 4;
Siarhei Vishniakou3531ae72021-02-02 12:12:27 -1000284 const nsecs_t publishTime = systemTime(SYSTEM_TIME_MONOTONIC);
Jeff Brown5912f952013-07-01 19:10:31 -0700285
Garfield Tanff1f1bb2020-01-28 13:24:04 -0800286 status = mPublisher->publishKeyEvent(seq, eventId, deviceId, source, displayId, hmac, action,
287 flags, keyCode, scanCode, metaState, repeatCount, downTime,
Siarhei Vishniakou9c858ac2020-01-23 14:20:11 -0600288 eventTime);
Jeff Brown5912f952013-07-01 19:10:31 -0700289 ASSERT_EQ(OK, status)
290 << "publisher publishKeyEvent should return OK";
291
Egor Paskoa0d32af2023-12-14 17:45:41 +0100292 waitUntilInputAvailable(*mConsumer);
Jeff Brown5912f952013-07-01 19:10:31 -0700293 uint32_t consumeSeq;
294 InputEvent* event;
Harry Cutts82c791c2023-03-10 17:15:07 +0000295 status = mConsumer->consume(&mEventFactory, /*consumeBatches=*/true, -1, &consumeSeq, &event);
Jeff Brown5912f952013-07-01 19:10:31 -0700296 ASSERT_EQ(OK, status)
297 << "consumer consume should return OK";
Egor Paskoa0d32af2023-12-14 17:45:41 +0100298 EXPECT_FALSE(mConsumer->probablyHasInput())
299 << "no events should be waiting after being consumed";
Jeff Brown5912f952013-07-01 19:10:31 -0700300
Yi Kong5bed83b2018-07-17 12:53:47 -0700301 ASSERT_TRUE(event != nullptr)
Jeff Brown5912f952013-07-01 19:10:31 -0700302 << "consumer should have returned non-NULL event";
Siarhei Vishniakou63b63612023-04-12 11:00:23 -0700303 ASSERT_EQ(InputEventType::KEY, event->getType()) << "consumer should have returned a key event";
Jeff Brown5912f952013-07-01 19:10:31 -0700304
305 KeyEvent* keyEvent = static_cast<KeyEvent*>(event);
306 EXPECT_EQ(seq, consumeSeq);
Garfield Tanff1f1bb2020-01-28 13:24:04 -0800307 EXPECT_EQ(eventId, keyEvent->getId());
Jeff Brown5912f952013-07-01 19:10:31 -0700308 EXPECT_EQ(deviceId, keyEvent->getDeviceId());
309 EXPECT_EQ(source, keyEvent->getSource());
Siarhei Vishniakoua62a8dd2018-06-08 21:17:33 +0100310 EXPECT_EQ(displayId, keyEvent->getDisplayId());
Siarhei Vishniakou9c858ac2020-01-23 14:20:11 -0600311 EXPECT_EQ(hmac, keyEvent->getHmac());
Jeff Brown5912f952013-07-01 19:10:31 -0700312 EXPECT_EQ(action, keyEvent->getAction());
313 EXPECT_EQ(flags, keyEvent->getFlags());
314 EXPECT_EQ(keyCode, keyEvent->getKeyCode());
315 EXPECT_EQ(scanCode, keyEvent->getScanCode());
316 EXPECT_EQ(metaState, keyEvent->getMetaState());
317 EXPECT_EQ(repeatCount, keyEvent->getRepeatCount());
318 EXPECT_EQ(downTime, keyEvent->getDownTime());
319 EXPECT_EQ(eventTime, keyEvent->getEventTime());
320
321 status = mConsumer->sendFinishedSignal(seq, true);
322 ASSERT_EQ(OK, status)
323 << "consumer sendFinishedSignal should return OK";
324
Siarhei Vishniakouf94ae022021-02-04 01:23:17 +0000325 Result<InputPublisher::ConsumerResponse> result = mPublisher->receiveConsumerResponse();
326 ASSERT_TRUE(result.ok()) << "receiveConsumerResponse should return OK";
327 ASSERT_TRUE(std::holds_alternative<InputPublisher::Finished>(*result));
328 const InputPublisher::Finished& finish = std::get<InputPublisher::Finished>(*result);
329 ASSERT_EQ(seq, finish.seq)
330 << "receiveConsumerResponse should have returned the original sequence number";
331 ASSERT_TRUE(finish.handled)
332 << "receiveConsumerResponse should have set handled to consumer's reply";
333 ASSERT_GE(finish.consumeTime, publishTime)
Siarhei Vishniakou3531ae72021-02-02 12:12:27 -1000334 << "finished signal's consume time should be greater than publish time";
Jeff Brown5912f952013-07-01 19:10:31 -0700335}
336
Siarhei Vishniakou6252af72023-09-20 09:00:38 -0700337void InputPublisherAndConsumerTest::publishAndConsumeMotionStream() {
338 const nsecs_t downTime = systemTime(SYSTEM_TIME_MONOTONIC);
Jeff Brown5912f952013-07-01 19:10:31 -0700339
Siarhei Vishniakou6252af72023-09-20 09:00:38 -0700340 publishAndConsumeMotionEvent(AMOTION_EVENT_ACTION_DOWN, downTime,
341 {Pointer{.id = 0, .x = 20, .y = 30}});
342
343 publishAndConsumeMotionEvent(POINTER_1_DOWN, downTime,
344 {Pointer{.id = 0, .x = 20, .y = 30},
345 Pointer{.id = 1, .x = 200, .y = 300}});
346
347 publishAndConsumeMotionEvent(POINTER_2_DOWN, downTime,
348 {Pointer{.id = 0, .x = 20, .y = 30},
349 Pointer{.id = 1, .x = 200, .y = 300},
350 Pointer{.id = 2, .x = 300, .y = 400}});
351
352 // Provide a consistent input stream - cancel the gesture that was started above
353 publishAndConsumeMotionEvent(AMOTION_EVENT_ACTION_CANCEL, downTime,
354 {Pointer{.id = 0, .x = 20, .y = 30},
355 Pointer{.id = 1, .x = 200, .y = 300},
356 Pointer{.id = 2, .x = 300, .y = 400}});
357}
358
Egor Paskoa0d32af2023-12-14 17:45:41 +0100359void InputPublisherAndConsumerTest::publishAndConsumeMotionDown(nsecs_t downTime) {
360 publishAndConsumeMotionEvent(AMOTION_EVENT_ACTION_DOWN, downTime,
361 {Pointer{.id = 0, .x = 20, .y = 30}});
362}
Siarhei Vishniakou6252af72023-09-20 09:00:38 -0700363
Egor Paskoa0d32af2023-12-14 17:45:41 +0100364void InputPublisherAndConsumerTest::publishAndConsumeBatchedMotionMove(nsecs_t downTime) {
365 uint32_t seq = mSeq++;
366 const std::vector<Pointer> pointers = {Pointer{.id = 0, .x = 20, .y = 30}};
367 PublishMotionArgs args(AMOTION_EVENT_ACTION_MOVE, downTime, pointers, seq);
368 const nsecs_t publishTime = systemTime(SYSTEM_TIME_MONOTONIC);
369 publishMotionEvent(*mPublisher, args);
Siarhei Vishniakou6252af72023-09-20 09:00:38 -0700370
Egor Paskoa0d32af2023-12-14 17:45:41 +0100371 // Consume leaving a batch behind.
372 uint32_t consumeSeq;
373 InputEvent* event;
374 status_t status = mConsumer->consume(&mEventFactory,
375 /*consumeBatches=*/false, -1, &consumeSeq, &event);
376 ASSERT_EQ(WOULD_BLOCK, status)
377 << "consumer consume should return WOULD_BLOCK when a new batch is started";
378 ASSERT_TRUE(mConsumer->hasPendingBatch()) << "consume should have created a batch";
379 EXPECT_TRUE(mConsumer->probablyHasInput())
380 << "should deterministically have input because there is a batch";
381 sendAndVerifyFinishedSignal(*mConsumer, *mPublisher, seq, publishTime);
Siarhei Vishniakou6252af72023-09-20 09:00:38 -0700382}
383
384void InputPublisherAndConsumerTest::publishAndConsumeMotionEvent(
Egor Paskoa0d32af2023-12-14 17:45:41 +0100385 int32_t action, nsecs_t downTime, const std::vector<Pointer>& pointers) {
386 uint32_t seq = mSeq++;
387 PublishMotionArgs args(action, downTime, pointers, seq);
388 nsecs_t publishTime = systemTime(SYSTEM_TIME_MONOTONIC);
389 publishMotionEvent(*mPublisher, args);
Jeff Brown5912f952013-07-01 19:10:31 -0700390
391 uint32_t consumeSeq;
392 InputEvent* event;
Egor Paskoa0d32af2023-12-14 17:45:41 +0100393 status_t status =
394 mConsumer->consume(&mEventFactory, /*consumeBatches=*/true, -1, &consumeSeq, &event);
395 ASSERT_EQ(OK, status) << "consumer consume should return OK";
Yi Kong5bed83b2018-07-17 12:53:47 -0700396 ASSERT_TRUE(event != nullptr)
Jeff Brown5912f952013-07-01 19:10:31 -0700397 << "consumer should have returned non-NULL event";
Siarhei Vishniakou63b63612023-04-12 11:00:23 -0700398 ASSERT_EQ(InputEventType::MOTION, event->getType())
Jeff Brown5912f952013-07-01 19:10:31 -0700399 << "consumer should have returned a motion event";
Jeff Brown5912f952013-07-01 19:10:31 -0700400 EXPECT_EQ(seq, consumeSeq);
Jeff Brown5912f952013-07-01 19:10:31 -0700401
Egor Paskoa0d32af2023-12-14 17:45:41 +0100402 verifyArgsEqualToEvent(args, static_cast<const MotionEvent&>(*event));
403 sendAndVerifyFinishedSignal(*mConsumer, *mPublisher, seq, publishTime);
Jeff Brown5912f952013-07-01 19:10:31 -0700404}
405
Siarhei Vishniakou6252af72023-09-20 09:00:38 -0700406void InputPublisherAndConsumerTest::publishAndConsumeFocusEvent() {
Siarhei Vishniakou7feb2ea2019-11-25 15:11:23 -0800407 status_t status;
408
409 constexpr uint32_t seq = 15;
Garfield Tanff1f1bb2020-01-28 13:24:04 -0800410 int32_t eventId = InputEvent::nextId();
Siarhei Vishniakou7feb2ea2019-11-25 15:11:23 -0800411 constexpr bool hasFocus = true;
Siarhei Vishniakou3531ae72021-02-02 12:12:27 -1000412 const nsecs_t publishTime = systemTime(SYSTEM_TIME_MONOTONIC);
Siarhei Vishniakou7feb2ea2019-11-25 15:11:23 -0800413
Antonio Kantek3cfec7b2021-11-05 18:26:17 -0700414 status = mPublisher->publishFocusEvent(seq, eventId, hasFocus);
arthurhung7632c332020-12-30 16:58:01 +0800415 ASSERT_EQ(OK, status) << "publisher publishFocusEvent should return OK";
Siarhei Vishniakou7feb2ea2019-11-25 15:11:23 -0800416
417 uint32_t consumeSeq;
418 InputEvent* event;
Harry Cutts82c791c2023-03-10 17:15:07 +0000419 status = mConsumer->consume(&mEventFactory, /*consumeBatches=*/true, -1, &consumeSeq, &event);
Siarhei Vishniakou7feb2ea2019-11-25 15:11:23 -0800420 ASSERT_EQ(OK, status) << "consumer consume should return OK";
421
422 ASSERT_TRUE(event != nullptr) << "consumer should have returned non-NULL event";
Siarhei Vishniakou63b63612023-04-12 11:00:23 -0700423 ASSERT_EQ(InputEventType::FOCUS, event->getType())
Siarhei Vishniakou7feb2ea2019-11-25 15:11:23 -0800424 << "consumer should have returned a focus event";
425
426 FocusEvent* focusEvent = static_cast<FocusEvent*>(event);
427 EXPECT_EQ(seq, consumeSeq);
Garfield Tanff1f1bb2020-01-28 13:24:04 -0800428 EXPECT_EQ(eventId, focusEvent->getId());
Siarhei Vishniakou7feb2ea2019-11-25 15:11:23 -0800429 EXPECT_EQ(hasFocus, focusEvent->getHasFocus());
Siarhei Vishniakou7feb2ea2019-11-25 15:11:23 -0800430
431 status = mConsumer->sendFinishedSignal(seq, true);
432 ASSERT_EQ(OK, status) << "consumer sendFinishedSignal should return OK";
433
Siarhei Vishniakouf94ae022021-02-04 01:23:17 +0000434 Result<InputPublisher::ConsumerResponse> result = mPublisher->receiveConsumerResponse();
435 ASSERT_TRUE(result.ok()) << "receiveConsumerResponse should return OK";
436 ASSERT_TRUE(std::holds_alternative<InputPublisher::Finished>(*result));
437 const InputPublisher::Finished& finish = std::get<InputPublisher::Finished>(*result);
Siarhei Vishniakoueedd0fc2021-03-12 09:50:36 +0000438
Siarhei Vishniakouf94ae022021-02-04 01:23:17 +0000439 ASSERT_EQ(seq, finish.seq)
440 << "receiveConsumerResponse should have returned the original sequence number";
441 ASSERT_TRUE(finish.handled)
442 << "receiveConsumerResponse should have set handled to consumer's reply";
443 ASSERT_GE(finish.consumeTime, publishTime)
Siarhei Vishniakou3531ae72021-02-02 12:12:27 -1000444 << "finished signal's consume time should be greater than publish time";
Siarhei Vishniakou7feb2ea2019-11-25 15:11:23 -0800445}
446
Siarhei Vishniakou6252af72023-09-20 09:00:38 -0700447void InputPublisherAndConsumerTest::publishAndConsumeCaptureEvent() {
Prabir Pradhan3f37b7b2020-11-10 16:50:18 -0800448 status_t status;
449
450 constexpr uint32_t seq = 42;
451 int32_t eventId = InputEvent::nextId();
452 constexpr bool captureEnabled = true;
Siarhei Vishniakou3531ae72021-02-02 12:12:27 -1000453 const nsecs_t publishTime = systemTime(SYSTEM_TIME_MONOTONIC);
Prabir Pradhan3f37b7b2020-11-10 16:50:18 -0800454
455 status = mPublisher->publishCaptureEvent(seq, eventId, captureEnabled);
arthurhung7632c332020-12-30 16:58:01 +0800456 ASSERT_EQ(OK, status) << "publisher publishCaptureEvent should return OK";
Prabir Pradhan3f37b7b2020-11-10 16:50:18 -0800457
458 uint32_t consumeSeq;
459 InputEvent* event;
Harry Cutts82c791c2023-03-10 17:15:07 +0000460 status = mConsumer->consume(&mEventFactory, /*consumeBatches=*/true, -1, &consumeSeq, &event);
Prabir Pradhan3f37b7b2020-11-10 16:50:18 -0800461 ASSERT_EQ(OK, status) << "consumer consume should return OK";
462
463 ASSERT_TRUE(event != nullptr) << "consumer should have returned non-NULL event";
Siarhei Vishniakou63b63612023-04-12 11:00:23 -0700464 ASSERT_EQ(InputEventType::CAPTURE, event->getType())
Prabir Pradhan3f37b7b2020-11-10 16:50:18 -0800465 << "consumer should have returned a capture event";
466
467 const CaptureEvent* captureEvent = static_cast<CaptureEvent*>(event);
468 EXPECT_EQ(seq, consumeSeq);
469 EXPECT_EQ(eventId, captureEvent->getId());
470 EXPECT_EQ(captureEnabled, captureEvent->getPointerCaptureEnabled());
471
472 status = mConsumer->sendFinishedSignal(seq, true);
473 ASSERT_EQ(OK, status) << "consumer sendFinishedSignal should return OK";
474
Siarhei Vishniakouf94ae022021-02-04 01:23:17 +0000475 Result<InputPublisher::ConsumerResponse> result = mPublisher->receiveConsumerResponse();
476 ASSERT_TRUE(result.ok()) << "receiveConsumerResponse should return OK";
477 ASSERT_TRUE(std::holds_alternative<InputPublisher::Finished>(*result));
478 const InputPublisher::Finished& finish = std::get<InputPublisher::Finished>(*result);
479 ASSERT_EQ(seq, finish.seq)
480 << "receiveConsumerResponse should have returned the original sequence number";
481 ASSERT_TRUE(finish.handled)
482 << "receiveConsumerResponse should have set handled to consumer's reply";
483 ASSERT_GE(finish.consumeTime, publishTime)
Siarhei Vishniakou3531ae72021-02-02 12:12:27 -1000484 << "finished signal's consume time should be greater than publish time";
Prabir Pradhan3f37b7b2020-11-10 16:50:18 -0800485}
486
Siarhei Vishniakou6252af72023-09-20 09:00:38 -0700487void InputPublisherAndConsumerTest::publishAndConsumeDragEvent() {
arthurhung7632c332020-12-30 16:58:01 +0800488 status_t status;
489
490 constexpr uint32_t seq = 15;
491 int32_t eventId = InputEvent::nextId();
492 constexpr bool isExiting = false;
493 constexpr float x = 10;
494 constexpr float y = 15;
495 const nsecs_t publishTime = systemTime(SYSTEM_TIME_MONOTONIC);
496
497 status = mPublisher->publishDragEvent(seq, eventId, x, y, isExiting);
498 ASSERT_EQ(OK, status) << "publisher publishDragEvent should return OK";
499
500 uint32_t consumeSeq;
501 InputEvent* event;
Harry Cutts82c791c2023-03-10 17:15:07 +0000502 status = mConsumer->consume(&mEventFactory, /*consumeBatches=*/true, -1, &consumeSeq, &event);
arthurhung7632c332020-12-30 16:58:01 +0800503 ASSERT_EQ(OK, status) << "consumer consume should return OK";
504
505 ASSERT_TRUE(event != nullptr) << "consumer should have returned non-NULL event";
Siarhei Vishniakou63b63612023-04-12 11:00:23 -0700506 ASSERT_EQ(InputEventType::DRAG, event->getType())
arthurhung7632c332020-12-30 16:58:01 +0800507 << "consumer should have returned a drag event";
508
Siarhei Vishniakoueedd0fc2021-03-12 09:50:36 +0000509 const DragEvent& dragEvent = static_cast<const DragEvent&>(*event);
arthurhung7632c332020-12-30 16:58:01 +0800510 EXPECT_EQ(seq, consumeSeq);
Siarhei Vishniakoueedd0fc2021-03-12 09:50:36 +0000511 EXPECT_EQ(eventId, dragEvent.getId());
512 EXPECT_EQ(isExiting, dragEvent.isExiting());
513 EXPECT_EQ(x, dragEvent.getX());
514 EXPECT_EQ(y, dragEvent.getY());
arthurhung7632c332020-12-30 16:58:01 +0800515
516 status = mConsumer->sendFinishedSignal(seq, true);
517 ASSERT_EQ(OK, status) << "consumer sendFinishedSignal should return OK";
518
Siarhei Vishniakouf94ae022021-02-04 01:23:17 +0000519 Result<InputPublisher::ConsumerResponse> result = mPublisher->receiveConsumerResponse();
520 ASSERT_TRUE(result.ok()) << "receiveConsumerResponse should return OK";
521 ASSERT_TRUE(std::holds_alternative<InputPublisher::Finished>(*result));
522 const InputPublisher::Finished& finish = std::get<InputPublisher::Finished>(*result);
523 ASSERT_EQ(seq, finish.seq)
524 << "receiveConsumerResponse should have returned the original sequence number";
525 ASSERT_TRUE(finish.handled)
526 << "receiveConsumerResponse should have set handled to consumer's reply";
527 ASSERT_GE(finish.consumeTime, publishTime)
arthurhung7632c332020-12-30 16:58:01 +0800528 << "finished signal's consume time should be greater than publish time";
529}
530
Siarhei Vishniakou6252af72023-09-20 09:00:38 -0700531void InputPublisherAndConsumerTest::publishAndConsumeTouchModeEvent() {
Antonio Kantek7cdf8ef2021-07-13 18:04:53 -0700532 status_t status;
533
534 constexpr uint32_t seq = 15;
535 int32_t eventId = InputEvent::nextId();
536 constexpr bool touchModeEnabled = true;
537 const nsecs_t publishTime = systemTime(SYSTEM_TIME_MONOTONIC);
538
539 status = mPublisher->publishTouchModeEvent(seq, eventId, touchModeEnabled);
540 ASSERT_EQ(OK, status) << "publisher publishTouchModeEvent should return OK";
541
542 uint32_t consumeSeq;
543 InputEvent* event;
Harry Cutts82c791c2023-03-10 17:15:07 +0000544 status = mConsumer->consume(&mEventFactory, /*consumeBatches=*/true, -1, &consumeSeq, &event);
Antonio Kantek7cdf8ef2021-07-13 18:04:53 -0700545 ASSERT_EQ(OK, status) << "consumer consume should return OK";
546
547 ASSERT_TRUE(event != nullptr) << "consumer should have returned non-NULL event";
Siarhei Vishniakou63b63612023-04-12 11:00:23 -0700548 ASSERT_EQ(InputEventType::TOUCH_MODE, event->getType())
Antonio Kantek7cdf8ef2021-07-13 18:04:53 -0700549 << "consumer should have returned a touch mode event";
550
551 const TouchModeEvent& touchModeEvent = static_cast<const TouchModeEvent&>(*event);
552 EXPECT_EQ(seq, consumeSeq);
553 EXPECT_EQ(eventId, touchModeEvent.getId());
554 EXPECT_EQ(touchModeEnabled, touchModeEvent.isInTouchMode());
555
556 status = mConsumer->sendFinishedSignal(seq, true);
557 ASSERT_EQ(OK, status) << "consumer sendFinishedSignal should return OK";
558
559 Result<InputPublisher::ConsumerResponse> result = mPublisher->receiveConsumerResponse();
560 ASSERT_TRUE(result.ok()) << "receiveConsumerResponse should return OK";
561 ASSERT_TRUE(std::holds_alternative<InputPublisher::Finished>(*result));
562 const InputPublisher::Finished& finish = std::get<InputPublisher::Finished>(*result);
563 ASSERT_EQ(seq, finish.seq)
564 << "receiveConsumerResponse should have returned the original sequence number";
565 ASSERT_TRUE(finish.handled)
566 << "receiveConsumerResponse should have set handled to consumer's reply";
567 ASSERT_GE(finish.consumeTime, publishTime)
568 << "finished signal's consume time should be greater than publish time";
569}
570
Siarhei Vishniakouf94ae022021-02-04 01:23:17 +0000571TEST_F(InputPublisherAndConsumerTest, SendTimeline) {
572 const int32_t inputEventId = 20;
573 std::array<nsecs_t, GraphicsTimeline::SIZE> graphicsTimeline;
574 graphicsTimeline[GraphicsTimeline::GPU_COMPLETED_TIME] = 30;
575 graphicsTimeline[GraphicsTimeline::PRESENT_TIME] = 40;
576 status_t status = mConsumer->sendTimeline(inputEventId, graphicsTimeline);
577 ASSERT_EQ(OK, status);
578
579 Result<InputPublisher::ConsumerResponse> result = mPublisher->receiveConsumerResponse();
580 ASSERT_TRUE(result.ok()) << "receiveConsumerResponse should return OK";
581 ASSERT_TRUE(std::holds_alternative<InputPublisher::Timeline>(*result));
582 const InputPublisher::Timeline& timeline = std::get<InputPublisher::Timeline>(*result);
583 ASSERT_EQ(inputEventId, timeline.inputEventId);
584 ASSERT_EQ(graphicsTimeline, timeline.graphicsTimeline);
585}
586
Jeff Brown5912f952013-07-01 19:10:31 -0700587TEST_F(InputPublisherAndConsumerTest, PublishKeyEvent_EndToEnd) {
Siarhei Vishniakou6252af72023-09-20 09:00:38 -0700588 ASSERT_NO_FATAL_FAILURE(publishAndConsumeKeyEvent());
Jeff Brown5912f952013-07-01 19:10:31 -0700589}
590
591TEST_F(InputPublisherAndConsumerTest, PublishMotionEvent_EndToEnd) {
Siarhei Vishniakou6252af72023-09-20 09:00:38 -0700592 ASSERT_NO_FATAL_FAILURE(publishAndConsumeMotionStream());
Jeff Brown5912f952013-07-01 19:10:31 -0700593}
594
Egor Paskoa0d32af2023-12-14 17:45:41 +0100595TEST_F(InputPublisherAndConsumerTest, PublishMotionMoveEvent_EndToEnd) {
596 // Publish a DOWN event before MOVE to pass the InputVerifier checks.
597 const nsecs_t downTime = systemTime(SYSTEM_TIME_MONOTONIC);
598 ASSERT_NO_FATAL_FAILURE(publishAndConsumeMotionDown(downTime));
599
600 // Publish the MOVE event and check expectations.
601 ASSERT_NO_FATAL_FAILURE(publishAndConsumeBatchedMotionMove(downTime));
602}
603
Siarhei Vishniakou7feb2ea2019-11-25 15:11:23 -0800604TEST_F(InputPublisherAndConsumerTest, PublishFocusEvent_EndToEnd) {
Siarhei Vishniakou6252af72023-09-20 09:00:38 -0700605 ASSERT_NO_FATAL_FAILURE(publishAndConsumeFocusEvent());
Siarhei Vishniakou7feb2ea2019-11-25 15:11:23 -0800606}
607
Prabir Pradhan3f37b7b2020-11-10 16:50:18 -0800608TEST_F(InputPublisherAndConsumerTest, PublishCaptureEvent_EndToEnd) {
Siarhei Vishniakou6252af72023-09-20 09:00:38 -0700609 ASSERT_NO_FATAL_FAILURE(publishAndConsumeCaptureEvent());
Prabir Pradhan3f37b7b2020-11-10 16:50:18 -0800610}
611
arthurhung7632c332020-12-30 16:58:01 +0800612TEST_F(InputPublisherAndConsumerTest, PublishDragEvent_EndToEnd) {
Siarhei Vishniakou6252af72023-09-20 09:00:38 -0700613 ASSERT_NO_FATAL_FAILURE(publishAndConsumeDragEvent());
arthurhung7632c332020-12-30 16:58:01 +0800614}
615
Antonio Kantek7cdf8ef2021-07-13 18:04:53 -0700616TEST_F(InputPublisherAndConsumerTest, PublishTouchModeEvent_EndToEnd) {
Siarhei Vishniakou6252af72023-09-20 09:00:38 -0700617 ASSERT_NO_FATAL_FAILURE(publishAndConsumeTouchModeEvent());
Antonio Kantek7cdf8ef2021-07-13 18:04:53 -0700618}
619
Siarhei Vishniakoub0fffdd2017-11-10 20:16:56 -0800620TEST_F(InputPublisherAndConsumerTest, PublishMotionEvent_WhenSequenceNumberIsZero_ReturnsError) {
Jeff Brown5912f952013-07-01 19:10:31 -0700621 status_t status;
Siarhei Vishniakoub0fffdd2017-11-10 20:16:56 -0800622 const size_t pointerCount = 1;
Jeff Brown5912f952013-07-01 19:10:31 -0700623 PointerProperties pointerProperties[pointerCount];
624 PointerCoords pointerCoords[pointerCount];
Siarhei Vishniakoub0fffdd2017-11-10 20:16:56 -0800625 for (size_t i = 0; i < pointerCount; i++) {
626 pointerProperties[i].clear();
627 pointerCoords[i].clear();
628 }
Jeff Brown5912f952013-07-01 19:10:31 -0700629
chaviw9eaa22c2020-07-01 16:21:27 -0700630 ui::Transform identityTransform;
Prabir Pradhanb9b18502021-08-26 12:30:32 -0700631 status =
632 mPublisher->publishMotionEvent(0, InputEvent::nextId(), 0, 0, 0, INVALID_HMAC, 0, 0, 0,
633 0, 0, 0, MotionClassification::NONE, identityTransform,
634 0, 0, AMOTION_EVENT_INVALID_CURSOR_POSITION,
635 AMOTION_EVENT_INVALID_CURSOR_POSITION, identityTransform,
636 0, 0, pointerCount, pointerProperties, pointerCoords);
Jeff Brown5912f952013-07-01 19:10:31 -0700637 ASSERT_EQ(BAD_VALUE, status)
638 << "publisher publishMotionEvent should return BAD_VALUE";
639}
640
Siarhei Vishniakoub0fffdd2017-11-10 20:16:56 -0800641TEST_F(InputPublisherAndConsumerTest, PublishMotionEvent_WhenPointerCountLessThan1_ReturnsError) {
642 status_t status;
643 const size_t pointerCount = 0;
644 PointerProperties pointerProperties[pointerCount];
645 PointerCoords pointerCoords[pointerCount];
646
chaviw9eaa22c2020-07-01 16:21:27 -0700647 ui::Transform identityTransform;
Prabir Pradhanb9b18502021-08-26 12:30:32 -0700648 status =
649 mPublisher->publishMotionEvent(1, InputEvent::nextId(), 0, 0, 0, INVALID_HMAC, 0, 0, 0,
650 0, 0, 0, MotionClassification::NONE, identityTransform,
651 0, 0, AMOTION_EVENT_INVALID_CURSOR_POSITION,
652 AMOTION_EVENT_INVALID_CURSOR_POSITION, identityTransform,
653 0, 0, pointerCount, pointerProperties, pointerCoords);
Siarhei Vishniakoub0fffdd2017-11-10 20:16:56 -0800654 ASSERT_EQ(BAD_VALUE, status)
655 << "publisher publishMotionEvent should return BAD_VALUE";
656}
657
658TEST_F(InputPublisherAndConsumerTest,
659 PublishMotionEvent_WhenPointerCountGreaterThanMax_ReturnsError) {
Jeff Brown5912f952013-07-01 19:10:31 -0700660 status_t status;
661 const size_t pointerCount = MAX_POINTERS + 1;
662 PointerProperties pointerProperties[pointerCount];
663 PointerCoords pointerCoords[pointerCount];
664 for (size_t i = 0; i < pointerCount; i++) {
665 pointerProperties[i].clear();
666 pointerCoords[i].clear();
667 }
668
chaviw9eaa22c2020-07-01 16:21:27 -0700669 ui::Transform identityTransform;
Prabir Pradhanb9b18502021-08-26 12:30:32 -0700670 status =
671 mPublisher->publishMotionEvent(1, InputEvent::nextId(), 0, 0, 0, INVALID_HMAC, 0, 0, 0,
672 0, 0, 0, MotionClassification::NONE, identityTransform,
673 0, 0, AMOTION_EVENT_INVALID_CURSOR_POSITION,
674 AMOTION_EVENT_INVALID_CURSOR_POSITION, identityTransform,
675 0, 0, pointerCount, pointerProperties, pointerCoords);
Jeff Brown5912f952013-07-01 19:10:31 -0700676 ASSERT_EQ(BAD_VALUE, status)
677 << "publisher publishMotionEvent should return BAD_VALUE";
678}
679
680TEST_F(InputPublisherAndConsumerTest, PublishMultipleEvents_EndToEnd) {
Siarhei Vishniakou6252af72023-09-20 09:00:38 -0700681 const nsecs_t downTime = systemTime(SYSTEM_TIME_MONOTONIC);
682
683 publishAndConsumeMotionEvent(AMOTION_EVENT_ACTION_DOWN, downTime,
684 {Pointer{.id = 0, .x = 20, .y = 30}});
685 ASSERT_NO_FATAL_FAILURE(publishAndConsumeKeyEvent());
686 publishAndConsumeMotionEvent(POINTER_1_DOWN, downTime,
687 {Pointer{.id = 0, .x = 20, .y = 30},
688 Pointer{.id = 1, .x = 200, .y = 300}});
689 ASSERT_NO_FATAL_FAILURE(publishAndConsumeFocusEvent());
690 publishAndConsumeMotionEvent(POINTER_2_DOWN, downTime,
691 {Pointer{.id = 0, .x = 20, .y = 30},
692 Pointer{.id = 1, .x = 200, .y = 300},
693 Pointer{.id = 2, .x = 200, .y = 300}});
694 ASSERT_NO_FATAL_FAILURE(publishAndConsumeKeyEvent());
695 ASSERT_NO_FATAL_FAILURE(publishAndConsumeCaptureEvent());
696 ASSERT_NO_FATAL_FAILURE(publishAndConsumeDragEvent());
697 // Provide a consistent input stream - cancel the gesture that was started above
698 publishAndConsumeMotionEvent(AMOTION_EVENT_ACTION_CANCEL, downTime,
699 {Pointer{.id = 0, .x = 20, .y = 30},
700 Pointer{.id = 1, .x = 200, .y = 300},
701 Pointer{.id = 2, .x = 200, .y = 300}});
702 ASSERT_NO_FATAL_FAILURE(publishAndConsumeKeyEvent());
703 ASSERT_NO_FATAL_FAILURE(publishAndConsumeTouchModeEvent());
Jeff Brown5912f952013-07-01 19:10:31 -0700704}
705
706} // namespace android