Skip to content

Commit 1d038d4

Browse files
committed
Consume full tap in EndToEndNativeInputTest
Currently, the injection inside the test is happening asynchronously. Occasionally, it seems that an inconsistent event stream is being sent. Without further debugging about how this is possible, a speculative fix is being made here by consuming a complete motion sequence after a tap is injected. This way, we know that the test must wait for the UP event to be received, thus hopefully preventing the next test from running and starting the asynchronous injection. To prevent misuse of 'consumeEvent' in the future, it is also being made private in this CL. Unfortunately, a bunch of other fields should also be private (but were not made so in the beginning, possibly a typo). As a result, some of the fields are now relied upon. These are kept as is to keep focus of this CL. Bug: 361264974 Test: atest libgui_test Flag: TEST_ONLY Change-Id: I99bac4022bab2b3aa106e0838b227f24eb512ea1
1 parent 2c6de79 commit 1d038d4

1 file changed

Lines changed: 20 additions & 18 deletions

File tree

libs/gui/tests/EndToEndNativeInputTest.cpp

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -183,20 +183,6 @@ class InputSurface {
183183
return std::make_unique<InputSurface>(surfaceControl, width, height);
184184
}
185185

186-
InputEvent* consumeEvent(std::chrono::milliseconds timeout = 3000ms) {
187-
mClientChannel->waitForMessage(timeout);
188-
189-
InputEvent* ev;
190-
uint32_t seqId;
191-
status_t consumed = mInputConsumer->consume(&mInputEventFactory, true, -1, &seqId, &ev);
192-
if (consumed != OK) {
193-
return nullptr;
194-
}
195-
status_t status = mInputConsumer->sendFinishedSignal(seqId, true);
196-
EXPECT_EQ(OK, status) << "Could not send finished signal";
197-
return ev;
198-
}
199-
200186
void assertFocusChange(bool hasFocus) {
201187
InputEvent* ev = consumeEvent();
202188
ASSERT_NE(ev, nullptr);
@@ -323,14 +309,30 @@ class InputSurface {
323309
}
324310

325311
public:
312+
// But should be private
313+
WindowInfo mInputInfo;
326314
sp<SurfaceControl> mSurfaceControl;
315+
316+
private:
327317
std::shared_ptr<InputChannel> mClientChannel;
328318
sp<IInputFlinger> mInputFlinger;
329319

330-
WindowInfo mInputInfo;
331-
332320
PreallocatedInputEventFactory mInputEventFactory;
333321
InputConsumer* mInputConsumer;
322+
323+
InputEvent* consumeEvent(std::chrono::milliseconds timeout = 3000ms) {
324+
mClientChannel->waitForMessage(timeout);
325+
326+
InputEvent* ev;
327+
uint32_t seqId;
328+
status_t consumed = mInputConsumer->consume(&mInputEventFactory, true, -1, &seqId, &ev);
329+
if (consumed != OK) {
330+
return nullptr;
331+
}
332+
status_t status = mInputConsumer->sendFinishedSignal(seqId, true);
333+
EXPECT_EQ(OK, status) << "Could not send finished signal";
334+
return ev;
335+
}
334336
};
335337

336338
class BlastInputSurface : public InputSurface {
@@ -458,7 +460,7 @@ TEST_F(InputSurfacesTest, can_receive_input) {
458460

459461
injectTap(101, 101);
460462

461-
EXPECT_NE(surface->consumeEvent(), nullptr);
463+
surface->expectTap(1, 1);
462464
}
463465

464466
/**
@@ -612,7 +614,7 @@ TEST_F(InputSurfacesTest, touchable_region) {
612614

613615
// A tap within the surface but outside the touchable region should not be sent to the surface.
614616
injectTap(20, 30);
615-
EXPECT_EQ(surface->consumeEvent(/*timeout=*/200ms), nullptr);
617+
surface->assertNoEvent();
616618

617619
injectTap(31, 52);
618620
surface->expectTap(20, 30);

0 commit comments

Comments
 (0)