Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 32ca92da authored by Prabir Pradhan's avatar Prabir Pradhan Committed by Android (Google) Code Review
Browse files

Merge "Add test to verify external stylus connection does not interrupt touch" into main

parents 1d7c8c81 85cf63e0
Loading
Loading
Loading
Loading
+52 −0
Original line number Diff line number Diff line
@@ -1356,6 +1356,7 @@ protected:
        ASSERT_NO_FATAL_FAILURE(mFakePolicy->assertInputDevicesChanged());
        ASSERT_NO_FATAL_FAILURE(mTestListener->assertNotifyInputDevicesChangedWasCalled());
        ASSERT_NO_FATAL_FAILURE(mTestListener->assertNotifyConfigurationChangedWasCalled());
        mTestListener->clearNotifyDeviceResetCalls();
    }
    void TearDown() override {
@@ -1828,6 +1829,57 @@ TEST_F(TouchIntegrationTest, NotifiesPolicyWhenStylusGestureStarted) {
    ASSERT_NO_FATAL_FAILURE(mFakePolicy->assertStylusGestureNotified(mDeviceInfo.getId()));
}
TEST_F(TouchIntegrationTest, ExternalStylusConnectedDuringTouchGesture) {
    ASSERT_NO_FATAL_FAILURE(
            mTestListener->assertNotifyDeviceResetWasCalled(WithDeviceId(mDeviceInfo.getId())));
    ASSERT_NO_FATAL_FAILURE(mTestListener->assertNotifyDeviceResetWasNotCalled());
    const Point centerPoint = mDevice->getCenterPoint();
    // Down
    mDevice->sendSlot(FIRST_SLOT);
    mDevice->sendTrackingId(FIRST_TRACKING_ID);
    mDevice->sendDown(centerPoint);
    mDevice->sendSync();
    ASSERT_NO_FATAL_FAILURE(mTestListener->assertNotifyMotionWasCalled(
            WithMotionAction(AMOTION_EVENT_ACTION_DOWN)));
    // Move
    mDevice->sendMove(centerPoint + Point(1, 1));
    mDevice->sendSync();
    ASSERT_NO_FATAL_FAILURE(mTestListener->assertNotifyMotionWasCalled(
            WithMotionAction(AMOTION_EVENT_ACTION_MOVE)));
    // Connecting an external stylus mid-gesture should not interrupt the ongoing gesture stream.
    auto externalStylus = createUinputDevice<UinputExternalStylus>();
    ASSERT_NO_FATAL_FAILURE(mFakePolicy->assertInputDevicesChanged());
    ASSERT_NO_FATAL_FAILURE(mTestListener->assertNotifyConfigurationChangedWasCalled());
    const auto stylusInfo = findDeviceByName(externalStylus->getName());
    ASSERT_TRUE(stylusInfo);
    ASSERT_NO_FATAL_FAILURE(
            mTestListener->assertNotifyDeviceResetWasCalled(WithDeviceId(stylusInfo->getId())));
    ASSERT_NO_FATAL_FAILURE(mTestListener->assertNotifyDeviceResetWasNotCalled());
    // Move
    mDevice->sendMove(centerPoint + Point(2, 2));
    mDevice->sendSync();
    ASSERT_NO_FATAL_FAILURE(mTestListener->assertNotifyMotionWasCalled(
            WithMotionAction(AMOTION_EVENT_ACTION_MOVE)));
    // Disconnecting an external stylus mid-gesture should not interrupt the ongoing gesture stream.
    externalStylus.reset();
    ASSERT_NO_FATAL_FAILURE(mFakePolicy->assertInputDevicesChanged());
    ASSERT_NO_FATAL_FAILURE(mTestListener->assertNotifyConfigurationChangedWasCalled());
    ASSERT_NO_FATAL_FAILURE(mTestListener->assertNotifyMotionWasNotCalled());
    // Up
    mDevice->sendUp();
    mDevice->sendSync();
    ASSERT_NO_FATAL_FAILURE(
            mTestListener->assertNotifyMotionWasCalled(WithMotionAction(AMOTION_EVENT_ACTION_UP)));
    ASSERT_NO_FATAL_FAILURE(mTestListener->assertNotifyMotionWasNotCalled());
}
// --- StylusButtonIntegrationTest ---
// Verify the behavior of button presses reported by various kinds of styluses, including buttons
+12 −0
Original line number Diff line number Diff line
@@ -57,6 +57,18 @@ void TestInputListener::assertNotifyDeviceResetWasCalled(NotifyDeviceResetArgs*
                                           "Expected notifyDeviceReset() to have been called."));
}

void TestInputListener::clearNotifyDeviceResetCalls() {
    std::scoped_lock<std::mutex> lock(mLock);
    std::get<std::vector<NotifyDeviceResetArgs>>(mQueues).clear();
}

void TestInputListener::assertNotifyDeviceResetWasCalled(
        const ::testing::Matcher<NotifyDeviceResetArgs>& matcher) {
    NotifyDeviceResetArgs outEventArgs;
    ASSERT_NO_FATAL_FAILURE(assertNotifyDeviceResetWasCalled(&outEventArgs));
    ASSERT_THAT(outEventArgs, matcher);
}

void TestInputListener::assertNotifyDeviceResetWasNotCalled() {
    ASSERT_NO_FATAL_FAILURE(
            assertNotCalled<NotifyDeviceResetArgs>("notifyDeviceReset() should not be called."));
+4 −0
Original line number Diff line number Diff line
@@ -43,6 +43,10 @@ public:

    void assertNotifyConfigurationChangedWasNotCalled();

    void clearNotifyDeviceResetCalls();

    void assertNotifyDeviceResetWasCalled(const ::testing::Matcher<NotifyDeviceResetArgs>& matcher);

    void assertNotifyDeviceResetWasCalled(NotifyDeviceResetArgs* outEventArgs = nullptr);

    void assertNotifyDeviceResetWasNotCalled();
+4 −0
Original line number Diff line number Diff line
@@ -139,6 +139,10 @@ public:
        return mDeviceId == args.deviceId;
    }

    bool MatchAndExplain(const NotifyDeviceResetArgs& args, std::ostream*) const {
        return mDeviceId == args.deviceId;
    }

    bool MatchAndExplain(const InputEvent& event, std::ostream*) const {
        return mDeviceId == event.getDeviceId();
    }