blob: 332831febbc7dba80bf48650b21472784139efb5 [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
chaviw09c8d2d2020-08-24 15:48:26 -070017#include <attestation/HmacKeyManager.h>
Jeff Brown5912f952013-07-01 19:10:31 -070018#include <gtest/gtest.h>
chaviw3277faf2021-05-19 16:45:23 -050019#include <gui/constants.h>
Siarhei Vishniakou0438ca82024-03-12 14:27:25 -070020#include <input/InputConsumer.h>
Jeff Brown5912f952013-07-01 19:10:31 -070021#include <input/InputTransport.h>
Jeff Brown5912f952013-07-01 19:10:31 -070022
Siarhei Vishniakoueedd0fc2021-03-12 09:50:36 +000023using android::base::Result;
24
Jeff Brown5912f952013-07-01 19:10:31 -070025namespace android {
26
Siarhei Vishniakou6252af72023-09-20 09:00:38 -070027namespace {
28
29static constexpr float EPSILON = MotionEvent::ROUNDING_PRECISION;
30static constexpr int32_t POINTER_1_DOWN =
31 AMOTION_EVENT_ACTION_POINTER_DOWN | (1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT);
32static constexpr int32_t POINTER_2_DOWN =
33 AMOTION_EVENT_ACTION_POINTER_DOWN | (2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT);
34
35struct Pointer {
36 int32_t id;
37 float x;
38 float y;
39 bool isResampled = false;
40};
41
Egor Paskoa0d32af2023-12-14 17:45:41 +010042// A collection of arguments to be sent as publishMotionEvent(). The saved members of this struct
43// allow to check the expectations against the event acquired from the InputReceiver. To help
44// simplify expectation checking it carries members not present in MotionEvent, like |rawXScale|.
45struct PublishMotionArgs {
46 const int32_t action;
47 const nsecs_t downTime;
48 const uint32_t seq;
49 const int32_t eventId;
50 const int32_t deviceId = 1;
51 const uint32_t source = AINPUT_SOURCE_TOUCHSCREEN;
52 const int32_t displayId = ADISPLAY_ID_DEFAULT;
53 const int32_t actionButton = 0;
54 const int32_t edgeFlags = AMOTION_EVENT_EDGE_FLAG_TOP;
55 const int32_t metaState = AMETA_ALT_LEFT_ON | AMETA_ALT_ON;
56 const int32_t buttonState = AMOTION_EVENT_BUTTON_PRIMARY;
57 const MotionClassification classification = MotionClassification::AMBIGUOUS_GESTURE;
58 const float xScale = 2;
59 const float yScale = 3;
60 const float xOffset = -10;
61 const float yOffset = -20;
62 const float rawXScale = 4;
63 const float rawYScale = -5;
64 const float rawXOffset = -11;
65 const float rawYOffset = 42;
66 const float xPrecision = 0.25;
67 const float yPrecision = 0.5;
68 const float xCursorPosition = 1.3;
69 const float yCursorPosition = 50.6;
70 std::array<uint8_t, 32> hmac;
71 int32_t flags;
72 ui::Transform transform;
73 ui::Transform rawTransform;
74 const nsecs_t eventTime;
75 size_t pointerCount;
76 std::vector<PointerProperties> pointerProperties;
77 std::vector<PointerCoords> pointerCoords;
78
79 PublishMotionArgs(int32_t action, nsecs_t downTime, const std::vector<Pointer>& pointers,
80 const uint32_t seq);
81};
82
83PublishMotionArgs::PublishMotionArgs(int32_t inAction, nsecs_t inDownTime,
84 const std::vector<Pointer>& pointers, const uint32_t inSeq)
85 : action(inAction),
86 downTime(inDownTime),
87 seq(inSeq),
88 eventId(InputEvent::nextId()),
89 eventTime(systemTime(SYSTEM_TIME_MONOTONIC)) {
90 hmac = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
91 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31};
92
93 flags = AMOTION_EVENT_FLAG_WINDOW_IS_OBSCURED;
94 if (action == AMOTION_EVENT_ACTION_CANCEL) {
95 flags |= AMOTION_EVENT_FLAG_CANCELED;
96 }
97 pointerCount = pointers.size();
98 for (size_t i = 0; i < pointerCount; i++) {
99 pointerProperties.push_back({});
100 pointerProperties[i].clear();
101 pointerProperties[i].id = pointers[i].id;
102 pointerProperties[i].toolType = ToolType::FINGER;
103
104 pointerCoords.push_back({});
105 pointerCoords[i].clear();
106 pointerCoords[i].isResampled = pointers[i].isResampled;
107 pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_X, pointers[i].x);
108 pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_Y, pointers[i].y);
109 pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_PRESSURE, 0.5 * i);
110 pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_SIZE, 0.7 * i);
111 pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_TOUCH_MAJOR, 1.5 * i);
112 pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_TOUCH_MINOR, 1.7 * i);
113 pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_TOOL_MAJOR, 2.5 * i);
114 pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_TOOL_MAJOR, 2.7 * i);
115 pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_ORIENTATION, 3.5 * i);
116 }
117 transform.set({xScale, 0, xOffset, 0, yScale, yOffset, 0, 0, 1});
118 rawTransform.set({rawXScale, 0, rawXOffset, 0, rawYScale, rawYOffset, 0, 0, 1});
119}
120
121// Checks expectations against |motionEvent| acquired from an InputConsumer. Floating point
122// comparisons limit precision to EPSILON.
123void verifyArgsEqualToEvent(const PublishMotionArgs& args, const MotionEvent& motionEvent) {
124 EXPECT_EQ(args.eventId, motionEvent.getId());
125 EXPECT_EQ(args.deviceId, motionEvent.getDeviceId());
126 EXPECT_EQ(args.source, motionEvent.getSource());
127 EXPECT_EQ(args.displayId, motionEvent.getDisplayId());
128 EXPECT_EQ(args.hmac, motionEvent.getHmac());
129 EXPECT_EQ(args.action, motionEvent.getAction());
130 EXPECT_EQ(args.downTime, motionEvent.getDownTime());
131 EXPECT_EQ(args.flags, motionEvent.getFlags());
132 EXPECT_EQ(args.edgeFlags, motionEvent.getEdgeFlags());
133 EXPECT_EQ(args.metaState, motionEvent.getMetaState());
134 EXPECT_EQ(args.buttonState, motionEvent.getButtonState());
135 EXPECT_EQ(args.classification, motionEvent.getClassification());
136 EXPECT_EQ(args.transform, motionEvent.getTransform());
Prabir Pradhanadd8a4a2024-03-05 22:18:09 +0000137 EXPECT_NEAR((-args.rawXOffset / args.rawXScale) * args.xScale + args.xOffset,
138 motionEvent.getRawXOffset(), EPSILON);
139 EXPECT_NEAR((-args.rawYOffset / args.rawYScale) * args.yScale + args.yOffset,
140 motionEvent.getRawYOffset(), EPSILON);
Egor Paskoa0d32af2023-12-14 17:45:41 +0100141 EXPECT_EQ(args.xPrecision, motionEvent.getXPrecision());
142 EXPECT_EQ(args.yPrecision, motionEvent.getYPrecision());
143 EXPECT_NEAR(args.xCursorPosition, motionEvent.getRawXCursorPosition(), EPSILON);
144 EXPECT_NEAR(args.yCursorPosition, motionEvent.getRawYCursorPosition(), EPSILON);
145 EXPECT_NEAR(args.xCursorPosition * args.xScale + args.xOffset, motionEvent.getXCursorPosition(),
146 EPSILON);
147 EXPECT_NEAR(args.yCursorPosition * args.yScale + args.yOffset, motionEvent.getYCursorPosition(),
148 EPSILON);
149 EXPECT_EQ(args.rawTransform, motionEvent.getRawTransform());
150 EXPECT_EQ(args.eventTime, motionEvent.getEventTime());
151 EXPECT_EQ(args.pointerCount, motionEvent.getPointerCount());
152 EXPECT_EQ(0U, motionEvent.getHistorySize());
153
154 for (size_t i = 0; i < args.pointerCount; i++) {
155 SCOPED_TRACE(i);
156 EXPECT_EQ(args.pointerProperties[i].id, motionEvent.getPointerId(i));
157 EXPECT_EQ(args.pointerProperties[i].toolType, motionEvent.getToolType(i));
158
159 const auto& pc = args.pointerCoords[i];
160 EXPECT_EQ(pc, motionEvent.getSamplePointerCoords()[i]);
161
162 EXPECT_NEAR(pc.getX() * args.rawXScale + args.rawXOffset, motionEvent.getRawX(i), EPSILON);
163 EXPECT_NEAR(pc.getY() * args.rawYScale + args.rawYOffset, motionEvent.getRawY(i), EPSILON);
164 EXPECT_NEAR(pc.getX() * args.xScale + args.xOffset, motionEvent.getX(i), EPSILON);
165 EXPECT_NEAR(pc.getY() * args.yScale + args.yOffset, motionEvent.getY(i), EPSILON);
166 EXPECT_EQ(pc.getAxisValue(AMOTION_EVENT_AXIS_PRESSURE), motionEvent.getPressure(i));
167 EXPECT_EQ(pc.getAxisValue(AMOTION_EVENT_AXIS_SIZE), motionEvent.getSize(i));
168 EXPECT_EQ(pc.getAxisValue(AMOTION_EVENT_AXIS_TOUCH_MAJOR), motionEvent.getTouchMajor(i));
169 EXPECT_EQ(pc.getAxisValue(AMOTION_EVENT_AXIS_TOUCH_MINOR), motionEvent.getTouchMinor(i));
170 EXPECT_EQ(pc.getAxisValue(AMOTION_EVENT_AXIS_TOOL_MAJOR), motionEvent.getToolMajor(i));
171 EXPECT_EQ(pc.getAxisValue(AMOTION_EVENT_AXIS_TOOL_MINOR), motionEvent.getToolMinor(i));
172
173 // Calculate the orientation after scaling, keeping in mind that an orientation of 0 is
174 // "up", and the positive y direction is "down".
175 const float unscaledOrientation = pc.getAxisValue(AMOTION_EVENT_AXIS_ORIENTATION);
176 const float x = sinf(unscaledOrientation) * args.xScale;
177 const float y = -cosf(unscaledOrientation) * args.yScale;
178 EXPECT_EQ(atan2f(x, -y), motionEvent.getOrientation(i));
179 }
180}
181
182void publishMotionEvent(InputPublisher& publisher, const PublishMotionArgs& a) {
183 status_t status =
184 publisher.publishMotionEvent(a.seq, a.eventId, a.deviceId, a.source, a.displayId,
185 a.hmac, a.action, a.actionButton, a.flags, a.edgeFlags,
186 a.metaState, a.buttonState, a.classification, a.transform,
187 a.xPrecision, a.yPrecision, a.xCursorPosition,
188 a.yCursorPosition, a.rawTransform, a.downTime, a.eventTime,
189 a.pointerCount, a.pointerProperties.data(),
190 a.pointerCoords.data());
191 ASSERT_EQ(OK, status) << "publisher publishMotionEvent should return OK";
192}
193
194void sendAndVerifyFinishedSignal(InputConsumer& consumer, InputPublisher& publisher, uint32_t seq,
195 nsecs_t publishTime) {
196 status_t status = consumer.sendFinishedSignal(seq, false);
197 ASSERT_EQ(OK, status) << "consumer sendFinishedSignal should return OK";
198 Result<InputPublisher::ConsumerResponse> result = publisher.receiveConsumerResponse();
199 ASSERT_TRUE(result.ok()) << "receiveConsumerResponse should return OK";
200 ASSERT_TRUE(std::holds_alternative<InputPublisher::Finished>(*result));
201 const InputPublisher::Finished& finish = std::get<InputPublisher::Finished>(*result);
202 ASSERT_EQ(seq, finish.seq)
203 << "receiveConsumerResponse should have returned the original sequence number";
204 ASSERT_FALSE(finish.handled)
205 << "receiveConsumerResponse should have set handled to consumer's reply";
206 ASSERT_GE(finish.consumeTime, publishTime)
207 << "finished signal's consume time should be greater than publish time";
208}
209
210void waitUntilInputAvailable(const InputConsumer& inputConsumer) {
211 bool hasInput;
212 do {
213 // The probablyHasInput() can return false positive under rare circumstances uncontrollable
214 // by the tests. Re-request the availability in this case. Returning |false| for a long
215 // time is not intended, and would cause a test timeout.
216 hasInput = inputConsumer.probablyHasInput();
217 } while (!hasInput);
218}
219
Siarhei Vishniakou6252af72023-09-20 09:00:38 -0700220} // namespace
Prabir Pradhan00e029d2023-03-09 20:11:09 +0000221
Jeff Brown5912f952013-07-01 19:10:31 -0700222class InputPublisherAndConsumerTest : public testing::Test {
223protected:
Siarhei Vishniakoud2588272020-07-10 11:15:40 -0500224 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);
Jeff Brown5912f952013-07-01 19:10:31 -0700233
Siarhei Vishniakou7b9f4f52024-02-02 13:07:16 -0800234 mPublisher = std::make_unique<InputPublisher>(std::move(serverChannel));
235 mConsumer = std::make_unique<InputConsumer>(std::move(clientChannel));
Jeff Brown5912f952013-07-01 19:10:31 -0700236 }
237
Siarhei Vishniakou6252af72023-09-20 09:00:38 -0700238 void publishAndConsumeKeyEvent();
239 void publishAndConsumeMotionStream();
Egor Paskoa0d32af2023-12-14 17:45:41 +0100240 void publishAndConsumeMotionDown(nsecs_t downTime);
241 void publishAndConsumeBatchedMotionMove(nsecs_t downTime);
Siarhei Vishniakou6252af72023-09-20 09:00:38 -0700242 void publishAndConsumeFocusEvent();
243 void publishAndConsumeCaptureEvent();
244 void publishAndConsumeDragEvent();
245 void publishAndConsumeTouchModeEvent();
246 void publishAndConsumeMotionEvent(int32_t action, nsecs_t downTime,
247 const std::vector<Pointer>& pointers);
248
249private:
250 // The sequence number to use when publishing the next event
251 uint32_t mSeq = 1;
Jeff Brown5912f952013-07-01 19:10:31 -0700252};
253
254TEST_F(InputPublisherAndConsumerTest, GetChannel_ReturnsTheChannel) {
Siarhei Vishniakou7b9f4f52024-02-02 13:07:16 -0800255 ASSERT_EQ(mPublisher->getChannel().getConnectionToken(),
Siarhei Vishniakoua1188f52020-10-20 20:14:52 -0500256 mConsumer->getChannel()->getConnectionToken());
Jeff Brown5912f952013-07-01 19:10:31 -0700257}
258
Siarhei Vishniakou6252af72023-09-20 09:00:38 -0700259void InputPublisherAndConsumerTest::publishAndConsumeKeyEvent() {
Jeff Brown5912f952013-07-01 19:10:31 -0700260 status_t status;
261
Siarhei Vishniakou6252af72023-09-20 09:00:38 -0700262 const uint32_t seq = mSeq++;
Garfield Tanff1f1bb2020-01-28 13:24:04 -0800263 int32_t eventId = InputEvent::nextId();
Siarhei Vishniakoua62a8dd2018-06-08 21:17:33 +0100264 constexpr int32_t deviceId = 1;
Siarhei Vishniakou3826d472020-01-27 10:44:40 -0600265 constexpr uint32_t source = AINPUT_SOURCE_KEYBOARD;
Siarhei Vishniakoua62a8dd2018-06-08 21:17:33 +0100266 constexpr int32_t displayId = ADISPLAY_ID_DEFAULT;
Siarhei Vishniakou9c858ac2020-01-23 14:20:11 -0600267 constexpr std::array<uint8_t, 32> hmac = {31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21,
268 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10,
269 9, 8, 7, 6, 5, 4, 3, 2, 1, 0};
Siarhei Vishniakoua62a8dd2018-06-08 21:17:33 +0100270 constexpr int32_t action = AKEY_EVENT_ACTION_DOWN;
271 constexpr int32_t flags = AKEY_EVENT_FLAG_FROM_SYSTEM;
272 constexpr int32_t keyCode = AKEYCODE_ENTER;
273 constexpr int32_t scanCode = 13;
274 constexpr int32_t metaState = AMETA_ALT_LEFT_ON | AMETA_ALT_ON;
275 constexpr int32_t repeatCount = 1;
276 constexpr nsecs_t downTime = 3;
277 constexpr nsecs_t eventTime = 4;
Siarhei Vishniakou3531ae72021-02-02 12:12:27 -1000278 const nsecs_t publishTime = systemTime(SYSTEM_TIME_MONOTONIC);
Jeff Brown5912f952013-07-01 19:10:31 -0700279
Garfield Tanff1f1bb2020-01-28 13:24:04 -0800280 status = mPublisher->publishKeyEvent(seq, eventId, deviceId, source, displayId, hmac, action,
281 flags, keyCode, scanCode, metaState, repeatCount, downTime,
Siarhei Vishniakou9c858ac2020-01-23 14:20:11 -0600282 eventTime);
Jeff Brown5912f952013-07-01 19:10:31 -0700283 ASSERT_EQ(OK, status)
284 << "publisher publishKeyEvent should return OK";
285
Egor Paskoa0d32af2023-12-14 17:45:41 +0100286 waitUntilInputAvailable(*mConsumer);
Jeff Brown5912f952013-07-01 19:10:31 -0700287 uint32_t consumeSeq;
288 InputEvent* event;
Harry Cutts82c791c2023-03-10 17:15:07 +0000289 status = mConsumer->consume(&mEventFactory, /*consumeBatches=*/true, -1, &consumeSeq, &event);
Jeff Brown5912f952013-07-01 19:10:31 -0700290 ASSERT_EQ(OK, status)
291 << "consumer consume should return OK";
Egor Paskoa0d32af2023-12-14 17:45:41 +0100292 EXPECT_FALSE(mConsumer->probablyHasInput())
293 << "no events should be waiting after being consumed";
Jeff Brown5912f952013-07-01 19:10:31 -0700294
Yi Kong5bed83b2018-07-17 12:53:47 -0700295 ASSERT_TRUE(event != nullptr)
Jeff Brown5912f952013-07-01 19:10:31 -0700296 << "consumer should have returned non-NULL event";
Siarhei Vishniakou63b63612023-04-12 11:00:23 -0700297 ASSERT_EQ(InputEventType::KEY, event->getType()) << "consumer should have returned a key event";
Jeff Brown5912f952013-07-01 19:10:31 -0700298
299 KeyEvent* keyEvent = static_cast<KeyEvent*>(event);
300 EXPECT_EQ(seq, consumeSeq);
Garfield Tanff1f1bb2020-01-28 13:24:04 -0800301 EXPECT_EQ(eventId, keyEvent->getId());
Jeff Brown5912f952013-07-01 19:10:31 -0700302 EXPECT_EQ(deviceId, keyEvent->getDeviceId());
303 EXPECT_EQ(source, keyEvent->getSource());
Siarhei Vishniakoua62a8dd2018-06-08 21:17:33 +0100304 EXPECT_EQ(displayId, keyEvent->getDisplayId());
Siarhei Vishniakou9c858ac2020-01-23 14:20:11 -0600305 EXPECT_EQ(hmac, keyEvent->getHmac());
Jeff Brown5912f952013-07-01 19:10:31 -0700306 EXPECT_EQ(action, keyEvent->getAction());
307 EXPECT_EQ(flags, keyEvent->getFlags());
308 EXPECT_EQ(keyCode, keyEvent->getKeyCode());
309 EXPECT_EQ(scanCode, keyEvent->getScanCode());
310 EXPECT_EQ(metaState, keyEvent->getMetaState());
311 EXPECT_EQ(repeatCount, keyEvent->getRepeatCount());
312 EXPECT_EQ(downTime, keyEvent->getDownTime());
313 EXPECT_EQ(eventTime, keyEvent->getEventTime());
314
315 status = mConsumer->sendFinishedSignal(seq, true);
316 ASSERT_EQ(OK, status)
317 << "consumer sendFinishedSignal should return OK";
318
Siarhei Vishniakouf94ae022021-02-04 01:23:17 +0000319 Result<InputPublisher::ConsumerResponse> result = mPublisher->receiveConsumerResponse();
320 ASSERT_TRUE(result.ok()) << "receiveConsumerResponse should return OK";
321 ASSERT_TRUE(std::holds_alternative<InputPublisher::Finished>(*result));
322 const InputPublisher::Finished& finish = std::get<InputPublisher::Finished>(*result);
323 ASSERT_EQ(seq, finish.seq)
324 << "receiveConsumerResponse should have returned the original sequence number";
325 ASSERT_TRUE(finish.handled)
326 << "receiveConsumerResponse should have set handled to consumer's reply";
327 ASSERT_GE(finish.consumeTime, publishTime)
Siarhei Vishniakou3531ae72021-02-02 12:12:27 -1000328 << "finished signal's consume time should be greater than publish time";
Jeff Brown5912f952013-07-01 19:10:31 -0700329}
330
Siarhei Vishniakou6252af72023-09-20 09:00:38 -0700331void InputPublisherAndConsumerTest::publishAndConsumeMotionStream() {
332 const nsecs_t downTime = systemTime(SYSTEM_TIME_MONOTONIC);
Jeff Brown5912f952013-07-01 19:10:31 -0700333
Siarhei Vishniakou6252af72023-09-20 09:00:38 -0700334 publishAndConsumeMotionEvent(AMOTION_EVENT_ACTION_DOWN, downTime,
335 {Pointer{.id = 0, .x = 20, .y = 30}});
336
337 publishAndConsumeMotionEvent(POINTER_1_DOWN, downTime,
338 {Pointer{.id = 0, .x = 20, .y = 30},
339 Pointer{.id = 1, .x = 200, .y = 300}});
340
341 publishAndConsumeMotionEvent(POINTER_2_DOWN, downTime,
342 {Pointer{.id = 0, .x = 20, .y = 30},
343 Pointer{.id = 1, .x = 200, .y = 300},
344 Pointer{.id = 2, .x = 300, .y = 400}});
345
346 // Provide a consistent input stream - cancel the gesture that was started above
347 publishAndConsumeMotionEvent(AMOTION_EVENT_ACTION_CANCEL, 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
Egor Paskoa0d32af2023-12-14 17:45:41 +0100353void InputPublisherAndConsumerTest::publishAndConsumeMotionDown(nsecs_t downTime) {
354 publishAndConsumeMotionEvent(AMOTION_EVENT_ACTION_DOWN, downTime,
355 {Pointer{.id = 0, .x = 20, .y = 30}});
356}
Siarhei Vishniakou6252af72023-09-20 09:00:38 -0700357
Egor Paskoa0d32af2023-12-14 17:45:41 +0100358void InputPublisherAndConsumerTest::publishAndConsumeBatchedMotionMove(nsecs_t downTime) {
359 uint32_t seq = mSeq++;
360 const std::vector<Pointer> pointers = {Pointer{.id = 0, .x = 20, .y = 30}};
361 PublishMotionArgs args(AMOTION_EVENT_ACTION_MOVE, downTime, pointers, seq);
362 const nsecs_t publishTime = systemTime(SYSTEM_TIME_MONOTONIC);
363 publishMotionEvent(*mPublisher, args);
Siarhei Vishniakou6252af72023-09-20 09:00:38 -0700364
Egor Paskoa0d32af2023-12-14 17:45:41 +0100365 // Consume leaving a batch behind.
366 uint32_t consumeSeq;
367 InputEvent* event;
368 status_t status = mConsumer->consume(&mEventFactory,
369 /*consumeBatches=*/false, -1, &consumeSeq, &event);
370 ASSERT_EQ(WOULD_BLOCK, status)
371 << "consumer consume should return WOULD_BLOCK when a new batch is started";
372 ASSERT_TRUE(mConsumer->hasPendingBatch()) << "consume should have created a batch";
373 EXPECT_TRUE(mConsumer->probablyHasInput())
374 << "should deterministically have input because there is a batch";
375 sendAndVerifyFinishedSignal(*mConsumer, *mPublisher, seq, publishTime);
Siarhei Vishniakou6252af72023-09-20 09:00:38 -0700376}
377
378void InputPublisherAndConsumerTest::publishAndConsumeMotionEvent(
Egor Paskoa0d32af2023-12-14 17:45:41 +0100379 int32_t action, nsecs_t downTime, const std::vector<Pointer>& pointers) {
380 uint32_t seq = mSeq++;
381 PublishMotionArgs args(action, downTime, pointers, seq);
382 nsecs_t publishTime = systemTime(SYSTEM_TIME_MONOTONIC);
383 publishMotionEvent(*mPublisher, args);
Jeff Brown5912f952013-07-01 19:10:31 -0700384
385 uint32_t consumeSeq;
386 InputEvent* event;
Egor Paskoa0d32af2023-12-14 17:45:41 +0100387 status_t status =
388 mConsumer->consume(&mEventFactory, /*consumeBatches=*/true, -1, &consumeSeq, &event);
389 ASSERT_EQ(OK, status) << "consumer consume should return OK";
Yi Kong5bed83b2018-07-17 12:53:47 -0700390 ASSERT_TRUE(event != nullptr)
Jeff Brown5912f952013-07-01 19:10:31 -0700391 << "consumer should have returned non-NULL event";
Siarhei Vishniakou63b63612023-04-12 11:00:23 -0700392 ASSERT_EQ(InputEventType::MOTION, event->getType())
Jeff Brown5912f952013-07-01 19:10:31 -0700393 << "consumer should have returned a motion event";
Jeff Brown5912f952013-07-01 19:10:31 -0700394 EXPECT_EQ(seq, consumeSeq);
Jeff Brown5912f952013-07-01 19:10:31 -0700395
Egor Paskoa0d32af2023-12-14 17:45:41 +0100396 verifyArgsEqualToEvent(args, static_cast<const MotionEvent&>(*event));
397 sendAndVerifyFinishedSignal(*mConsumer, *mPublisher, seq, publishTime);
Jeff Brown5912f952013-07-01 19:10:31 -0700398}
399
Siarhei Vishniakou6252af72023-09-20 09:00:38 -0700400void InputPublisherAndConsumerTest::publishAndConsumeFocusEvent() {
Siarhei Vishniakou7feb2ea2019-11-25 15:11:23 -0800401 status_t status;
402
403 constexpr uint32_t seq = 15;
Garfield Tanff1f1bb2020-01-28 13:24:04 -0800404 int32_t eventId = InputEvent::nextId();
Siarhei Vishniakou7feb2ea2019-11-25 15:11:23 -0800405 constexpr bool hasFocus = true;
Siarhei Vishniakou3531ae72021-02-02 12:12:27 -1000406 const nsecs_t publishTime = systemTime(SYSTEM_TIME_MONOTONIC);
Siarhei Vishniakou7feb2ea2019-11-25 15:11:23 -0800407
Antonio Kantek3cfec7b2021-11-05 18:26:17 -0700408 status = mPublisher->publishFocusEvent(seq, eventId, hasFocus);
arthurhung7632c332020-12-30 16:58:01 +0800409 ASSERT_EQ(OK, status) << "publisher publishFocusEvent should return OK";
Siarhei Vishniakou7feb2ea2019-11-25 15:11:23 -0800410
411 uint32_t consumeSeq;
412 InputEvent* event;
Harry Cutts82c791c2023-03-10 17:15:07 +0000413 status = mConsumer->consume(&mEventFactory, /*consumeBatches=*/true, -1, &consumeSeq, &event);
Siarhei Vishniakou7feb2ea2019-11-25 15:11:23 -0800414 ASSERT_EQ(OK, status) << "consumer consume should return OK";
415
416 ASSERT_TRUE(event != nullptr) << "consumer should have returned non-NULL event";
Siarhei Vishniakou63b63612023-04-12 11:00:23 -0700417 ASSERT_EQ(InputEventType::FOCUS, event->getType())
Siarhei Vishniakou7feb2ea2019-11-25 15:11:23 -0800418 << "consumer should have returned a focus event";
419
420 FocusEvent* focusEvent = static_cast<FocusEvent*>(event);
421 EXPECT_EQ(seq, consumeSeq);
Garfield Tanff1f1bb2020-01-28 13:24:04 -0800422 EXPECT_EQ(eventId, focusEvent->getId());
Siarhei Vishniakou7feb2ea2019-11-25 15:11:23 -0800423 EXPECT_EQ(hasFocus, focusEvent->getHasFocus());
Siarhei Vishniakou7feb2ea2019-11-25 15:11:23 -0800424
425 status = mConsumer->sendFinishedSignal(seq, true);
426 ASSERT_EQ(OK, status) << "consumer sendFinishedSignal should return OK";
427
Siarhei Vishniakouf94ae022021-02-04 01:23:17 +0000428 Result<InputPublisher::ConsumerResponse> result = mPublisher->receiveConsumerResponse();
429 ASSERT_TRUE(result.ok()) << "receiveConsumerResponse should return OK";
430 ASSERT_TRUE(std::holds_alternative<InputPublisher::Finished>(*result));
431 const InputPublisher::Finished& finish = std::get<InputPublisher::Finished>(*result);
Siarhei Vishniakoueedd0fc2021-03-12 09:50:36 +0000432
Siarhei Vishniakouf94ae022021-02-04 01:23:17 +0000433 ASSERT_EQ(seq, finish.seq)
434 << "receiveConsumerResponse should have returned the original sequence number";
435 ASSERT_TRUE(finish.handled)
436 << "receiveConsumerResponse should have set handled to consumer's reply";
437 ASSERT_GE(finish.consumeTime, publishTime)
Siarhei Vishniakou3531ae72021-02-02 12:12:27 -1000438 << "finished signal's consume time should be greater than publish time";
Siarhei Vishniakou7feb2ea2019-11-25 15:11:23 -0800439}
440
Siarhei Vishniakou6252af72023-09-20 09:00:38 -0700441void InputPublisherAndConsumerTest::publishAndConsumeCaptureEvent() {
Prabir Pradhan3f37b7b2020-11-10 16:50:18 -0800442 status_t status;
443
444 constexpr uint32_t seq = 42;
445 int32_t eventId = InputEvent::nextId();
446 constexpr bool captureEnabled = true;
Siarhei Vishniakou3531ae72021-02-02 12:12:27 -1000447 const nsecs_t publishTime = systemTime(SYSTEM_TIME_MONOTONIC);
Prabir Pradhan3f37b7b2020-11-10 16:50:18 -0800448
449 status = mPublisher->publishCaptureEvent(seq, eventId, captureEnabled);
arthurhung7632c332020-12-30 16:58:01 +0800450 ASSERT_EQ(OK, status) << "publisher publishCaptureEvent should return OK";
Prabir Pradhan3f37b7b2020-11-10 16:50:18 -0800451
452 uint32_t consumeSeq;
453 InputEvent* event;
Harry Cutts82c791c2023-03-10 17:15:07 +0000454 status = mConsumer->consume(&mEventFactory, /*consumeBatches=*/true, -1, &consumeSeq, &event);
Prabir Pradhan3f37b7b2020-11-10 16:50:18 -0800455 ASSERT_EQ(OK, status) << "consumer consume should return OK";
456
457 ASSERT_TRUE(event != nullptr) << "consumer should have returned non-NULL event";
Siarhei Vishniakou63b63612023-04-12 11:00:23 -0700458 ASSERT_EQ(InputEventType::CAPTURE, event->getType())
Prabir Pradhan3f37b7b2020-11-10 16:50:18 -0800459 << "consumer should have returned a capture event";
460
461 const CaptureEvent* captureEvent = static_cast<CaptureEvent*>(event);
462 EXPECT_EQ(seq, consumeSeq);
463 EXPECT_EQ(eventId, captureEvent->getId());
464 EXPECT_EQ(captureEnabled, captureEvent->getPointerCaptureEnabled());
465
466 status = mConsumer->sendFinishedSignal(seq, true);
467 ASSERT_EQ(OK, status) << "consumer sendFinishedSignal should return OK";
468
Siarhei Vishniakouf94ae022021-02-04 01:23:17 +0000469 Result<InputPublisher::ConsumerResponse> result = mPublisher->receiveConsumerResponse();
470 ASSERT_TRUE(result.ok()) << "receiveConsumerResponse should return OK";
471 ASSERT_TRUE(std::holds_alternative<InputPublisher::Finished>(*result));
472 const InputPublisher::Finished& finish = std::get<InputPublisher::Finished>(*result);
473 ASSERT_EQ(seq, finish.seq)
474 << "receiveConsumerResponse should have returned the original sequence number";
475 ASSERT_TRUE(finish.handled)
476 << "receiveConsumerResponse should have set handled to consumer's reply";
477 ASSERT_GE(finish.consumeTime, publishTime)
Siarhei Vishniakou3531ae72021-02-02 12:12:27 -1000478 << "finished signal's consume time should be greater than publish time";
Prabir Pradhan3f37b7b2020-11-10 16:50:18 -0800479}
480
Siarhei Vishniakou6252af72023-09-20 09:00:38 -0700481void InputPublisherAndConsumerTest::publishAndConsumeDragEvent() {
arthurhung7632c332020-12-30 16:58:01 +0800482 status_t status;
483
484 constexpr uint32_t seq = 15;
485 int32_t eventId = InputEvent::nextId();
486 constexpr bool isExiting = false;
487 constexpr float x = 10;
488 constexpr float y = 15;
489 const nsecs_t publishTime = systemTime(SYSTEM_TIME_MONOTONIC);
490
491 status = mPublisher->publishDragEvent(seq, eventId, x, y, isExiting);
492 ASSERT_EQ(OK, status) << "publisher publishDragEvent should return OK";
493
494 uint32_t consumeSeq;
495 InputEvent* event;
Harry Cutts82c791c2023-03-10 17:15:07 +0000496 status = mConsumer->consume(&mEventFactory, /*consumeBatches=*/true, -1, &consumeSeq, &event);
arthurhung7632c332020-12-30 16:58:01 +0800497 ASSERT_EQ(OK, status) << "consumer consume should return OK";
498
499 ASSERT_TRUE(event != nullptr) << "consumer should have returned non-NULL event";
Siarhei Vishniakou63b63612023-04-12 11:00:23 -0700500 ASSERT_EQ(InputEventType::DRAG, event->getType())
arthurhung7632c332020-12-30 16:58:01 +0800501 << "consumer should have returned a drag event";
502
Siarhei Vishniakoueedd0fc2021-03-12 09:50:36 +0000503 const DragEvent& dragEvent = static_cast<const DragEvent&>(*event);
arthurhung7632c332020-12-30 16:58:01 +0800504 EXPECT_EQ(seq, consumeSeq);
Siarhei Vishniakoueedd0fc2021-03-12 09:50:36 +0000505 EXPECT_EQ(eventId, dragEvent.getId());
506 EXPECT_EQ(isExiting, dragEvent.isExiting());
507 EXPECT_EQ(x, dragEvent.getX());
508 EXPECT_EQ(y, dragEvent.getY());
arthurhung7632c332020-12-30 16:58:01 +0800509
510 status = mConsumer->sendFinishedSignal(seq, true);
511 ASSERT_EQ(OK, status) << "consumer sendFinishedSignal should return OK";
512
Siarhei Vishniakouf94ae022021-02-04 01:23:17 +0000513 Result<InputPublisher::ConsumerResponse> result = mPublisher->receiveConsumerResponse();
514 ASSERT_TRUE(result.ok()) << "receiveConsumerResponse should return OK";
515 ASSERT_TRUE(std::holds_alternative<InputPublisher::Finished>(*result));
516 const InputPublisher::Finished& finish = std::get<InputPublisher::Finished>(*result);
517 ASSERT_EQ(seq, finish.seq)
518 << "receiveConsumerResponse should have returned the original sequence number";
519 ASSERT_TRUE(finish.handled)
520 << "receiveConsumerResponse should have set handled to consumer's reply";
521 ASSERT_GE(finish.consumeTime, publishTime)
arthurhung7632c332020-12-30 16:58:01 +0800522 << "finished signal's consume time should be greater than publish time";
523}
524
Siarhei Vishniakou6252af72023-09-20 09:00:38 -0700525void InputPublisherAndConsumerTest::publishAndConsumeTouchModeEvent() {
Antonio Kantek7cdf8ef2021-07-13 18:04:53 -0700526 status_t status;
527
528 constexpr uint32_t seq = 15;
529 int32_t eventId = InputEvent::nextId();
530 constexpr bool touchModeEnabled = true;
531 const nsecs_t publishTime = systemTime(SYSTEM_TIME_MONOTONIC);
532
533 status = mPublisher->publishTouchModeEvent(seq, eventId, touchModeEnabled);
534 ASSERT_EQ(OK, status) << "publisher publishTouchModeEvent should return OK";
535
536 uint32_t consumeSeq;
537 InputEvent* event;
Harry Cutts82c791c2023-03-10 17:15:07 +0000538 status = mConsumer->consume(&mEventFactory, /*consumeBatches=*/true, -1, &consumeSeq, &event);
Antonio Kantek7cdf8ef2021-07-13 18:04:53 -0700539 ASSERT_EQ(OK, status) << "consumer consume should return OK";
540
541 ASSERT_TRUE(event != nullptr) << "consumer should have returned non-NULL event";
Siarhei Vishniakou63b63612023-04-12 11:00:23 -0700542 ASSERT_EQ(InputEventType::TOUCH_MODE, event->getType())
Antonio Kantek7cdf8ef2021-07-13 18:04:53 -0700543 << "consumer should have returned a touch mode event";
544
545 const TouchModeEvent& touchModeEvent = static_cast<const TouchModeEvent&>(*event);
546 EXPECT_EQ(seq, consumeSeq);
547 EXPECT_EQ(eventId, touchModeEvent.getId());
548 EXPECT_EQ(touchModeEnabled, touchModeEvent.isInTouchMode());
549
550 status = mConsumer->sendFinishedSignal(seq, true);
551 ASSERT_EQ(OK, status) << "consumer sendFinishedSignal should return OK";
552
553 Result<InputPublisher::ConsumerResponse> result = mPublisher->receiveConsumerResponse();
554 ASSERT_TRUE(result.ok()) << "receiveConsumerResponse should return OK";
555 ASSERT_TRUE(std::holds_alternative<InputPublisher::Finished>(*result));
556 const InputPublisher::Finished& finish = std::get<InputPublisher::Finished>(*result);
557 ASSERT_EQ(seq, finish.seq)
558 << "receiveConsumerResponse should have returned the original sequence number";
559 ASSERT_TRUE(finish.handled)
560 << "receiveConsumerResponse should have set handled to consumer's reply";
561 ASSERT_GE(finish.consumeTime, publishTime)
562 << "finished signal's consume time should be greater than publish time";
563}
564
Siarhei Vishniakouf94ae022021-02-04 01:23:17 +0000565TEST_F(InputPublisherAndConsumerTest, SendTimeline) {
566 const int32_t inputEventId = 20;
567 std::array<nsecs_t, GraphicsTimeline::SIZE> graphicsTimeline;
568 graphicsTimeline[GraphicsTimeline::GPU_COMPLETED_TIME] = 30;
569 graphicsTimeline[GraphicsTimeline::PRESENT_TIME] = 40;
570 status_t status = mConsumer->sendTimeline(inputEventId, graphicsTimeline);
571 ASSERT_EQ(OK, status);
572
573 Result<InputPublisher::ConsumerResponse> result = mPublisher->receiveConsumerResponse();
574 ASSERT_TRUE(result.ok()) << "receiveConsumerResponse should return OK";
575 ASSERT_TRUE(std::holds_alternative<InputPublisher::Timeline>(*result));
576 const InputPublisher::Timeline& timeline = std::get<InputPublisher::Timeline>(*result);
577 ASSERT_EQ(inputEventId, timeline.inputEventId);
578 ASSERT_EQ(graphicsTimeline, timeline.graphicsTimeline);
579}
580
Jeff Brown5912f952013-07-01 19:10:31 -0700581TEST_F(InputPublisherAndConsumerTest, PublishKeyEvent_EndToEnd) {
Siarhei Vishniakou6252af72023-09-20 09:00:38 -0700582 ASSERT_NO_FATAL_FAILURE(publishAndConsumeKeyEvent());
Jeff Brown5912f952013-07-01 19:10:31 -0700583}
584
585TEST_F(InputPublisherAndConsumerTest, PublishMotionEvent_EndToEnd) {
Siarhei Vishniakou6252af72023-09-20 09:00:38 -0700586 ASSERT_NO_FATAL_FAILURE(publishAndConsumeMotionStream());
Jeff Brown5912f952013-07-01 19:10:31 -0700587}
588
Egor Paskoa0d32af2023-12-14 17:45:41 +0100589TEST_F(InputPublisherAndConsumerTest, PublishMotionMoveEvent_EndToEnd) {
590 // Publish a DOWN event before MOVE to pass the InputVerifier checks.
591 const nsecs_t downTime = systemTime(SYSTEM_TIME_MONOTONIC);
592 ASSERT_NO_FATAL_FAILURE(publishAndConsumeMotionDown(downTime));
593
594 // Publish the MOVE event and check expectations.
595 ASSERT_NO_FATAL_FAILURE(publishAndConsumeBatchedMotionMove(downTime));
596}
597
Siarhei Vishniakou7feb2ea2019-11-25 15:11:23 -0800598TEST_F(InputPublisherAndConsumerTest, PublishFocusEvent_EndToEnd) {
Siarhei Vishniakou6252af72023-09-20 09:00:38 -0700599 ASSERT_NO_FATAL_FAILURE(publishAndConsumeFocusEvent());
Siarhei Vishniakou7feb2ea2019-11-25 15:11:23 -0800600}
601
Prabir Pradhan3f37b7b2020-11-10 16:50:18 -0800602TEST_F(InputPublisherAndConsumerTest, PublishCaptureEvent_EndToEnd) {
Siarhei Vishniakou6252af72023-09-20 09:00:38 -0700603 ASSERT_NO_FATAL_FAILURE(publishAndConsumeCaptureEvent());
Prabir Pradhan3f37b7b2020-11-10 16:50:18 -0800604}
605
arthurhung7632c332020-12-30 16:58:01 +0800606TEST_F(InputPublisherAndConsumerTest, PublishDragEvent_EndToEnd) {
Siarhei Vishniakou6252af72023-09-20 09:00:38 -0700607 ASSERT_NO_FATAL_FAILURE(publishAndConsumeDragEvent());
arthurhung7632c332020-12-30 16:58:01 +0800608}
609
Antonio Kantek7cdf8ef2021-07-13 18:04:53 -0700610TEST_F(InputPublisherAndConsumerTest, PublishTouchModeEvent_EndToEnd) {
Siarhei Vishniakou6252af72023-09-20 09:00:38 -0700611 ASSERT_NO_FATAL_FAILURE(publishAndConsumeTouchModeEvent());
Antonio Kantek7cdf8ef2021-07-13 18:04:53 -0700612}
613
Siarhei Vishniakoub0fffdd2017-11-10 20:16:56 -0800614TEST_F(InputPublisherAndConsumerTest, PublishMotionEvent_WhenSequenceNumberIsZero_ReturnsError) {
Jeff Brown5912f952013-07-01 19:10:31 -0700615 status_t status;
Siarhei Vishniakoub0fffdd2017-11-10 20:16:56 -0800616 const size_t pointerCount = 1;
Jeff Brown5912f952013-07-01 19:10:31 -0700617 PointerProperties pointerProperties[pointerCount];
618 PointerCoords pointerCoords[pointerCount];
Siarhei Vishniakoub0fffdd2017-11-10 20:16:56 -0800619 for (size_t i = 0; i < pointerCount; i++) {
620 pointerProperties[i].clear();
621 pointerCoords[i].clear();
622 }
Jeff Brown5912f952013-07-01 19:10:31 -0700623
chaviw9eaa22c2020-07-01 16:21:27 -0700624 ui::Transform identityTransform;
Prabir Pradhanb9b18502021-08-26 12:30:32 -0700625 status =
626 mPublisher->publishMotionEvent(0, InputEvent::nextId(), 0, 0, 0, INVALID_HMAC, 0, 0, 0,
627 0, 0, 0, MotionClassification::NONE, identityTransform,
628 0, 0, AMOTION_EVENT_INVALID_CURSOR_POSITION,
629 AMOTION_EVENT_INVALID_CURSOR_POSITION, identityTransform,
630 0, 0, pointerCount, pointerProperties, pointerCoords);
Jeff Brown5912f952013-07-01 19:10:31 -0700631 ASSERT_EQ(BAD_VALUE, status)
632 << "publisher publishMotionEvent should return BAD_VALUE";
633}
634
Siarhei Vishniakoub0fffdd2017-11-10 20:16:56 -0800635TEST_F(InputPublisherAndConsumerTest, PublishMotionEvent_WhenPointerCountLessThan1_ReturnsError) {
636 status_t status;
637 const size_t pointerCount = 0;
638 PointerProperties pointerProperties[pointerCount];
639 PointerCoords pointerCoords[pointerCount];
640
chaviw9eaa22c2020-07-01 16:21:27 -0700641 ui::Transform identityTransform;
Prabir Pradhanb9b18502021-08-26 12:30:32 -0700642 status =
643 mPublisher->publishMotionEvent(1, InputEvent::nextId(), 0, 0, 0, INVALID_HMAC, 0, 0, 0,
644 0, 0, 0, MotionClassification::NONE, identityTransform,
645 0, 0, AMOTION_EVENT_INVALID_CURSOR_POSITION,
646 AMOTION_EVENT_INVALID_CURSOR_POSITION, identityTransform,
647 0, 0, pointerCount, pointerProperties, pointerCoords);
Siarhei Vishniakoub0fffdd2017-11-10 20:16:56 -0800648 ASSERT_EQ(BAD_VALUE, status)
649 << "publisher publishMotionEvent should return BAD_VALUE";
650}
651
652TEST_F(InputPublisherAndConsumerTest,
653 PublishMotionEvent_WhenPointerCountGreaterThanMax_ReturnsError) {
Jeff Brown5912f952013-07-01 19:10:31 -0700654 status_t status;
655 const size_t pointerCount = MAX_POINTERS + 1;
656 PointerProperties pointerProperties[pointerCount];
657 PointerCoords pointerCoords[pointerCount];
658 for (size_t i = 0; i < pointerCount; i++) {
659 pointerProperties[i].clear();
660 pointerCoords[i].clear();
661 }
662
chaviw9eaa22c2020-07-01 16:21:27 -0700663 ui::Transform identityTransform;
Prabir Pradhanb9b18502021-08-26 12:30:32 -0700664 status =
665 mPublisher->publishMotionEvent(1, InputEvent::nextId(), 0, 0, 0, INVALID_HMAC, 0, 0, 0,
666 0, 0, 0, MotionClassification::NONE, identityTransform,
667 0, 0, AMOTION_EVENT_INVALID_CURSOR_POSITION,
668 AMOTION_EVENT_INVALID_CURSOR_POSITION, identityTransform,
669 0, 0, pointerCount, pointerProperties, pointerCoords);
Jeff Brown5912f952013-07-01 19:10:31 -0700670 ASSERT_EQ(BAD_VALUE, status)
671 << "publisher publishMotionEvent should return BAD_VALUE";
672}
673
674TEST_F(InputPublisherAndConsumerTest, PublishMultipleEvents_EndToEnd) {
Siarhei Vishniakou6252af72023-09-20 09:00:38 -0700675 const nsecs_t downTime = systemTime(SYSTEM_TIME_MONOTONIC);
676
677 publishAndConsumeMotionEvent(AMOTION_EVENT_ACTION_DOWN, downTime,
678 {Pointer{.id = 0, .x = 20, .y = 30}});
679 ASSERT_NO_FATAL_FAILURE(publishAndConsumeKeyEvent());
680 publishAndConsumeMotionEvent(POINTER_1_DOWN, downTime,
681 {Pointer{.id = 0, .x = 20, .y = 30},
682 Pointer{.id = 1, .x = 200, .y = 300}});
683 ASSERT_NO_FATAL_FAILURE(publishAndConsumeFocusEvent());
684 publishAndConsumeMotionEvent(POINTER_2_DOWN, downTime,
685 {Pointer{.id = 0, .x = 20, .y = 30},
686 Pointer{.id = 1, .x = 200, .y = 300},
687 Pointer{.id = 2, .x = 200, .y = 300}});
688 ASSERT_NO_FATAL_FAILURE(publishAndConsumeKeyEvent());
689 ASSERT_NO_FATAL_FAILURE(publishAndConsumeCaptureEvent());
690 ASSERT_NO_FATAL_FAILURE(publishAndConsumeDragEvent());
691 // Provide a consistent input stream - cancel the gesture that was started above
692 publishAndConsumeMotionEvent(AMOTION_EVENT_ACTION_CANCEL, downTime,
693 {Pointer{.id = 0, .x = 20, .y = 30},
694 Pointer{.id = 1, .x = 200, .y = 300},
695 Pointer{.id = 2, .x = 200, .y = 300}});
696 ASSERT_NO_FATAL_FAILURE(publishAndConsumeKeyEvent());
697 ASSERT_NO_FATAL_FAILURE(publishAndConsumeTouchModeEvent());
Jeff Brown5912f952013-07-01 19:10:31 -0700698}
699
700} // namespace android