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

Commit 8935a802 authored by Siarhei Vishniakou's avatar Siarhei Vishniakou
Browse files

Refactor inputfilter tests

We are currently storing several variables from notify*args inside the
fake policy, in order to check that we received the right values later.
This is inconvenient because it's not clear that these variables are
specifically for the inputfilter test.
Store these in the input event instead.

Bug: none
Test: atest inputflinger_tests
Change-Id: I34dba73eeacf7dd58b10691c6fad3d5206daa780
parent 486d5b74
Loading
Loading
Loading
Loading
+22 −42
Original line number Original line Diff line number Diff line
@@ -50,43 +50,35 @@ protected:


public:
public:
    FakeInputDispatcherPolicy() {
    FakeInputDispatcherPolicy() {
        mInputEventFiltered = false;
        mTime = -1;
        mAction = -1;
        mDisplayId = -1;
        mOnPointerDownToken.clear();
        mOnPointerDownToken.clear();
    }
    }


    void assertFilterInputEventWasCalledWithExpectedArgs(const NotifyMotionArgs* args) {
    void assertFilterInputEventWasCalled(const NotifyKeyArgs& args) {
        ASSERT_TRUE(mInputEventFiltered)
        ASSERT_NE(nullptr, mFilteredEvent) << "Expected filterInputEvent() to have been called.";
                << "Expected filterInputEvent() to have been called.";
        ASSERT_EQ(mFilteredEvent->getType(), AINPUT_EVENT_TYPE_KEY);


        ASSERT_EQ(mTime, args->eventTime)
        const KeyEvent& keyEvent = static_cast<const KeyEvent&>(*mFilteredEvent);
                << "Expected time of filtered event was not matched";
        ASSERT_EQ(keyEvent.getEventTime(), args.eventTime);
        ASSERT_EQ(mAction, args->action)
        ASSERT_EQ(keyEvent.getAction(), args.action);
                << "Expected action of filtered event was not matched";
        ASSERT_EQ(keyEvent.getDisplayId(), args.displayId);
        ASSERT_EQ(mDisplayId, args->displayId)
                << "Expected displayId of filtered event was not matched";


        reset();
        reset();
    }
    }


    void assertFilterInputEventWasCalledWithExpectedArgs(const NotifyKeyArgs* args) {
    void assertFilterInputEventWasCalled(const NotifyMotionArgs& args) {
        ASSERT_TRUE(mInputEventFiltered)
        ASSERT_NE(nullptr, mFilteredEvent) << "Expected filterInputEvent() to have been called.";
                << "Expected filterInputEvent() to have been called.";
        ASSERT_EQ(mFilteredEvent->getType(), AINPUT_EVENT_TYPE_MOTION);


        ASSERT_EQ(mTime, args->eventTime)
        const MotionEvent& motionEvent = static_cast<const MotionEvent&>(*mFilteredEvent);
                << "Expected time of filtered event was not matched";
        ASSERT_EQ(motionEvent.getEventTime(), args.eventTime);
        ASSERT_EQ(mAction, args->action)
        ASSERT_EQ(motionEvent.getAction(), args.action);
                << "Expected action of filtered event was not matched";
        ASSERT_EQ(motionEvent.getDisplayId(), args.displayId);
        ASSERT_EQ(mDisplayId, args->displayId)
                << "Expected displayId of filtered event was not matched";


        reset();
        reset();
    }
    }


    void assertFilterInputEventWasNotCalled() {
    void assertFilterInputEventWasNotCalled() {
        ASSERT_FALSE(mInputEventFiltered)
        ASSERT_EQ(nullptr, mFilteredEvent)
                << "Expected filterInputEvent() to not have been called.";
                << "Expected filterInputEvent() to not have been called.";
    }
    }


@@ -97,10 +89,7 @@ public:
    }
    }


private:
private:
    bool mInputEventFiltered;
    std::unique_ptr<InputEvent> mFilteredEvent;
    nsecs_t mTime;
    int32_t mAction;
    int32_t mDisplayId;
    sp<IBinder> mOnPointerDownToken;
    sp<IBinder> mOnPointerDownToken;


    virtual void notifyConfigurationChanged(nsecs_t) {
    virtual void notifyConfigurationChanged(nsecs_t) {
@@ -122,26 +111,20 @@ private:
        *outConfig = mConfig;
        *outConfig = mConfig;
    }
    }


    virtual bool filterInputEvent(const InputEvent* inputEvent, uint32_t policyFlags) {
    virtual bool filterInputEvent(const InputEvent* inputEvent, uint32_t policyFlags) override {
        switch (inputEvent->getType()) {
        switch (inputEvent->getType()) {
            case AINPUT_EVENT_TYPE_KEY: {
            case AINPUT_EVENT_TYPE_KEY: {
                const KeyEvent* keyEvent = static_cast<const KeyEvent*>(inputEvent);
                const KeyEvent* keyEvent = static_cast<const KeyEvent*>(inputEvent);
                mTime = keyEvent->getEventTime();
                mFilteredEvent = std::make_unique<KeyEvent>(*keyEvent);
                mAction = keyEvent->getAction();
                mDisplayId = keyEvent->getDisplayId();
                break;
                break;
            }
            }


            case AINPUT_EVENT_TYPE_MOTION: {
            case AINPUT_EVENT_TYPE_MOTION: {
                const MotionEvent* motionEvent = static_cast<const MotionEvent*>(inputEvent);
                const MotionEvent* motionEvent = static_cast<const MotionEvent*>(inputEvent);
                mTime = motionEvent->getEventTime();
                mFilteredEvent = std::make_unique<MotionEvent>(*motionEvent);
                mAction = motionEvent->getAction();
                mDisplayId = motionEvent->getDisplayId();
                break;
                break;
            }
            }
        }
        }

        mInputEventFiltered = true;
        return true;
        return true;
    }
    }


@@ -176,10 +159,7 @@ private:
    }
    }


    void reset() {
    void reset() {
        mInputEventFiltered = false;
        mFilteredEvent = nullptr;
        mTime = -1;
        mAction = -1;
        mDisplayId = -1;
        mOnPointerDownToken.clear();
        mOnPointerDownToken.clear();
    }
    }
};
};
@@ -931,7 +911,7 @@ protected:
        mDispatcher->notifyMotion(&motionArgs);
        mDispatcher->notifyMotion(&motionArgs);


        if (expectToBeFiltered) {
        if (expectToBeFiltered) {
            mFakePolicy->assertFilterInputEventWasCalledWithExpectedArgs(&motionArgs);
            mFakePolicy->assertFilterInputEventWasCalled(motionArgs);
        } else {
        } else {
            mFakePolicy->assertFilterInputEventWasNotCalled();
            mFakePolicy->assertFilterInputEventWasNotCalled();
        }
        }
@@ -946,7 +926,7 @@ protected:
        mDispatcher->notifyKey(&keyArgs);
        mDispatcher->notifyKey(&keyArgs);


        if (expectToBeFiltered) {
        if (expectToBeFiltered) {
            mFakePolicy->assertFilterInputEventWasCalledWithExpectedArgs(&keyArgs);
            mFakePolicy->assertFilterInputEventWasCalled(keyArgs);
        } else {
        } else {
            mFakePolicy->assertFilterInputEventWasNotCalled();
            mFakePolicy->assertFilterInputEventWasNotCalled();
        }
        }