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

Commit 28d8c7db authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge changes Iac34e9bc,I19c84ab5

* changes:
  Rename some variables in InputDispatcher_test
  Refactor filterInputEvent asserts
parents 7c6e924b b9b15358
Loading
Loading
Loading
Loading
+50 −72
Original line number Original line Diff line number Diff line
@@ -54,33 +54,16 @@ public:
    }
    }


    void assertFilterInputEventWasCalled(const NotifyKeyArgs& args) {
    void assertFilterInputEventWasCalled(const NotifyKeyArgs& args) {
        ASSERT_NE(nullptr, mFilteredEvent) << "Expected filterInputEvent() to have been called.";
        assertFilterInputEventWasCalled(AINPUT_EVENT_TYPE_KEY, args.eventTime, args.action,
        ASSERT_EQ(mFilteredEvent->getType(), AINPUT_EVENT_TYPE_KEY);
                                        args.displayId);

        const KeyEvent& keyEvent = static_cast<const KeyEvent&>(*mFilteredEvent);
        ASSERT_EQ(keyEvent.getEventTime(), args.eventTime);
        ASSERT_EQ(keyEvent.getAction(), args.action);
        ASSERT_EQ(keyEvent.getDisplayId(), args.displayId);

        reset();
    }
    }


    void assertFilterInputEventWasCalled(const NotifyMotionArgs& args) {
    void assertFilterInputEventWasCalled(const NotifyMotionArgs& args) {
        ASSERT_NE(nullptr, mFilteredEvent) << "Expected filterInputEvent() to have been called.";
        assertFilterInputEventWasCalled(AINPUT_EVENT_TYPE_MOTION, args.eventTime, args.action,
        ASSERT_EQ(mFilteredEvent->getType(), AINPUT_EVENT_TYPE_MOTION);
                                        args.displayId);

        const MotionEvent& motionEvent = static_cast<const MotionEvent&>(*mFilteredEvent);
        ASSERT_EQ(motionEvent.getEventTime(), args.eventTime);
        ASSERT_EQ(motionEvent.getAction(), args.action);
        ASSERT_EQ(motionEvent.getDisplayId(), args.displayId);

        reset();
    }
    }


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


    void assertOnPointerDownEquals(const sp<IBinder>& touchedToken) {
    void assertOnPointerDownEquals(const sp<IBinder>& touchedToken) {
        ASSERT_EQ(mOnPointerDownToken, touchedToken)
        ASSERT_EQ(mOnPointerDownToken, touchedToken)
@@ -158,10 +141,29 @@ private:
        mOnPointerDownToken = newToken;
        mOnPointerDownToken = newToken;
    }
    }


    void reset() {
    void assertFilterInputEventWasCalled(int type, nsecs_t eventTime, int32_t action,
                                         int32_t displayId) {
        ASSERT_NE(nullptr, mFilteredEvent) << "Expected filterInputEvent() to have been called.";
        ASSERT_EQ(mFilteredEvent->getType(), type);

        if (type == AINPUT_EVENT_TYPE_KEY) {
            const KeyEvent& keyEvent = static_cast<const KeyEvent&>(*mFilteredEvent);
            EXPECT_EQ(keyEvent.getEventTime(), eventTime);
            EXPECT_EQ(keyEvent.getAction(), action);
            EXPECT_EQ(keyEvent.getDisplayId(), displayId);
        } else if (type == AINPUT_EVENT_TYPE_MOTION) {
            const MotionEvent& motionEvent = static_cast<const MotionEvent&>(*mFilteredEvent);
            EXPECT_EQ(motionEvent.getEventTime(), eventTime);
            EXPECT_EQ(motionEvent.getAction(), action);
            EXPECT_EQ(motionEvent.getDisplayId(), displayId);
        } else {
            FAIL() << "Unknown type: " << type;
        }

        mFilteredEvent = nullptr;
        mFilteredEvent = nullptr;
        mOnPointerDownToken.clear();
    }
    }

    void reset() { mOnPointerDownToken.clear(); }
};
};




@@ -634,10 +636,7 @@ TEST_F(InputDispatcherTest, SetInputWindow_SingleWindowTouch) {
    sp<FakeWindowHandle> window = new FakeWindowHandle(application, mDispatcher, "Fake Window",
    sp<FakeWindowHandle> window = new FakeWindowHandle(application, mDispatcher, "Fake Window",
            ADISPLAY_ID_DEFAULT);
            ADISPLAY_ID_DEFAULT);


    std::vector<sp<InputWindowHandle>> inputWindowHandles;
    mDispatcher->setInputWindows({window}, ADISPLAY_ID_DEFAULT);
    inputWindowHandles.push_back(window);

    mDispatcher->setInputWindows(inputWindowHandles, ADISPLAY_ID_DEFAULT);
    ASSERT_EQ(INPUT_EVENT_INJECTION_SUCCEEDED, injectMotionDown(mDispatcher,
    ASSERT_EQ(INPUT_EVENT_INJECTION_SUCCEEDED, injectMotionDown(mDispatcher,
            AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT))
            AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT))
            << "Inject motion event should return INPUT_EVENT_INJECTION_SUCCEEDED";
            << "Inject motion event should return INPUT_EVENT_INJECTION_SUCCEEDED";
@@ -654,11 +653,7 @@ TEST_F(InputDispatcherTest, SetInputWindow_MultiWindowsTouch) {
    sp<FakeWindowHandle> windowSecond = new FakeWindowHandle(application, mDispatcher, "Second",
    sp<FakeWindowHandle> windowSecond = new FakeWindowHandle(application, mDispatcher, "Second",
            ADISPLAY_ID_DEFAULT);
            ADISPLAY_ID_DEFAULT);


    std::vector<sp<InputWindowHandle>> inputWindowHandles;
    mDispatcher->setInputWindows({windowTop, windowSecond}, ADISPLAY_ID_DEFAULT);
    inputWindowHandles.push_back(windowTop);
    inputWindowHandles.push_back(windowSecond);

    mDispatcher->setInputWindows(inputWindowHandles, ADISPLAY_ID_DEFAULT);
    ASSERT_EQ(INPUT_EVENT_INJECTION_SUCCEEDED, injectMotionDown(mDispatcher,
    ASSERT_EQ(INPUT_EVENT_INJECTION_SUCCEEDED, injectMotionDown(mDispatcher,
            AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT))
            AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT))
            << "Inject motion event should return INPUT_EVENT_INJECTION_SUCCEEDED";
            << "Inject motion event should return INPUT_EVENT_INJECTION_SUCCEEDED";
@@ -680,11 +675,8 @@ TEST_F(InputDispatcherTest, SetInputWindow_FocusedWindow) {


    // Expect one focus window exist in display.
    // Expect one focus window exist in display.
    windowSecond->setFocus();
    windowSecond->setFocus();
    std::vector<sp<InputWindowHandle>> inputWindowHandles;
    inputWindowHandles.push_back(windowTop);
    inputWindowHandles.push_back(windowSecond);


    mDispatcher->setInputWindows(inputWindowHandles, ADISPLAY_ID_DEFAULT);
    mDispatcher->setInputWindows({windowTop, windowSecond}, ADISPLAY_ID_DEFAULT);
    ASSERT_EQ(INPUT_EVENT_INJECTION_SUCCEEDED, injectKeyDown(mDispatcher))
    ASSERT_EQ(INPUT_EVENT_INJECTION_SUCCEEDED, injectKeyDown(mDispatcher))
            << "Inject key event should return INPUT_EVENT_INJECTION_SUCCEEDED";
            << "Inject key event should return INPUT_EVENT_INJECTION_SUCCEEDED";


@@ -706,11 +698,8 @@ TEST_F(InputDispatcherTest, SetInputWindow_FocusPriority) {
    // Display has two focused windows. Add them to inputWindowsHandles in z-order (top most first)
    // Display has two focused windows. Add them to inputWindowsHandles in z-order (top most first)
    windowTop->setFocus();
    windowTop->setFocus();
    windowSecond->setFocus();
    windowSecond->setFocus();
    std::vector<sp<InputWindowHandle>> inputWindowHandles;
    inputWindowHandles.push_back(windowTop);
    inputWindowHandles.push_back(windowSecond);


    mDispatcher->setInputWindows(inputWindowHandles, ADISPLAY_ID_DEFAULT);
    mDispatcher->setInputWindows({windowTop, windowSecond}, ADISPLAY_ID_DEFAULT);
    ASSERT_EQ(INPUT_EVENT_INJECTION_SUCCEEDED, injectKeyDown(mDispatcher))
    ASSERT_EQ(INPUT_EVENT_INJECTION_SUCCEEDED, injectKeyDown(mDispatcher))
            << "Inject key event should return INPUT_EVENT_INJECTION_SUCCEEDED";
            << "Inject key event should return INPUT_EVENT_INJECTION_SUCCEEDED";


@@ -732,12 +721,9 @@ TEST_F(InputDispatcherTest, SetInputWindow_InputWindowInfo) {


    windowTop->setFocus();
    windowTop->setFocus();
    windowSecond->setFocus();
    windowSecond->setFocus();
    std::vector<sp<InputWindowHandle>> inputWindowHandles;
    inputWindowHandles.push_back(windowTop);
    inputWindowHandles.push_back(windowSecond);
    // Release channel for window is no longer valid.
    // Release channel for window is no longer valid.
    windowTop->releaseChannel();
    windowTop->releaseChannel();
    mDispatcher->setInputWindows(inputWindowHandles, ADISPLAY_ID_DEFAULT);
    mDispatcher->setInputWindows({windowTop, windowSecond}, ADISPLAY_ID_DEFAULT);


    // Test inject a key down, should dispatch to a valid window.
    // Test inject a key down, should dispatch to a valid window.
    ASSERT_EQ(INPUT_EVENT_INJECTION_SUCCEEDED, injectKeyDown(mDispatcher))
    ASSERT_EQ(INPUT_EVENT_INJECTION_SUCCEEDED, injectKeyDown(mDispatcher))
@@ -762,8 +748,7 @@ TEST_F(InputDispatcherTest, DispatchMouseEventsUnderCursor) {


    mDispatcher->setFocusedApplication(ADISPLAY_ID_DEFAULT, application);
    mDispatcher->setFocusedApplication(ADISPLAY_ID_DEFAULT, application);


    std::vector<sp<InputWindowHandle>> inputWindowHandles{windowLeft, windowRight};
    mDispatcher->setInputWindows({windowLeft, windowRight}, ADISPLAY_ID_DEFAULT);
    mDispatcher->setInputWindows(inputWindowHandles, ADISPLAY_ID_DEFAULT);


    // Inject an event with coordinate in the area of right window, with mouse cursor in the area of
    // Inject an event with coordinate in the area of right window, with mouse cursor in the area of
    // left window. This event should be dispatched to the left window.
    // left window. This event should be dispatched to the left window.
@@ -784,25 +769,22 @@ public:
        application1 = new FakeApplicationHandle();
        application1 = new FakeApplicationHandle();
        windowInPrimary = new FakeWindowHandle(application1, mDispatcher, "D_1",
        windowInPrimary = new FakeWindowHandle(application1, mDispatcher, "D_1",
                ADISPLAY_ID_DEFAULT);
                ADISPLAY_ID_DEFAULT);
        std::vector<sp<InputWindowHandle>> inputWindowHandles;

        inputWindowHandles.push_back(windowInPrimary);
        // Set focus window for primary display, but focused display would be second one.
        // Set focus window for primary display, but focused display would be second one.
        mDispatcher->setFocusedApplication(ADISPLAY_ID_DEFAULT, application1);
        mDispatcher->setFocusedApplication(ADISPLAY_ID_DEFAULT, application1);
        windowInPrimary->setFocus();
        windowInPrimary->setFocus();
        mDispatcher->setInputWindows(inputWindowHandles, ADISPLAY_ID_DEFAULT);
        mDispatcher->setInputWindows({windowInPrimary}, ADISPLAY_ID_DEFAULT);


        application2 = new FakeApplicationHandle();
        application2 = new FakeApplicationHandle();
        windowInSecondary = new FakeWindowHandle(application2, mDispatcher, "D_2",
        windowInSecondary = new FakeWindowHandle(application2, mDispatcher, "D_2",
                SECOND_DISPLAY_ID);
                SECOND_DISPLAY_ID);
        // Set focus to second display window.
        // Set focus to second display window.
        std::vector<sp<InputWindowHandle>> inputWindowHandles_Second;
        inputWindowHandles_Second.push_back(windowInSecondary);
        // Set focus display to second one.
        // Set focus display to second one.
        mDispatcher->setFocusedDisplay(SECOND_DISPLAY_ID);
        mDispatcher->setFocusedDisplay(SECOND_DISPLAY_ID);
        // Set focus window for second display.
        // Set focus window for second display.
        mDispatcher->setFocusedApplication(SECOND_DISPLAY_ID, application2);
        mDispatcher->setFocusedApplication(SECOND_DISPLAY_ID, application2);
        windowInSecondary->setFocus();
        windowInSecondary->setFocus();
        mDispatcher->setInputWindows(inputWindowHandles_Second, SECOND_DISPLAY_ID);
        mDispatcher->setInputWindows({windowInSecondary}, SECOND_DISPLAY_ID);
    }
    }


    virtual void TearDown() {
    virtual void TearDown() {
@@ -850,9 +832,8 @@ TEST_F(InputDispatcherFocusOnTwoDisplaysTest, SetInputWindow_MultiDisplayFocus)
    windowInPrimary->assertNoEvents();
    windowInPrimary->assertNoEvents();
    windowInSecondary->consumeKeyDown(ADISPLAY_ID_NONE);
    windowInSecondary->consumeKeyDown(ADISPLAY_ID_NONE);


    // Remove secondary display.
    // Remove all windows in secondary display.
    std::vector<sp<InputWindowHandle>> noWindows;
    mDispatcher->setInputWindows({}, SECOND_DISPLAY_ID);
    mDispatcher->setInputWindows(noWindows, SECOND_DISPLAY_ID);


    // Expect old focus should receive a cancel event.
    // Expect old focus should receive a cancel event.
    windowInSecondary->consumeEvent(AINPUT_EVENT_TYPE_KEY, AKEY_EVENT_ACTION_UP, ADISPLAY_ID_NONE,
    windowInSecondary->consumeEvent(AINPUT_EVENT_TYPE_KEY, AKEY_EVENT_ACTION_UP, ADISPLAY_ID_NONE,
@@ -1012,34 +993,31 @@ class InputDispatcherOnPointerDownOutsideFocus : public InputDispatcherTest {
        // window.
        // window.
        mUnfocusedWindow->setLayoutParamFlags(InputWindowInfo::FLAG_NOT_TOUCH_MODAL);
        mUnfocusedWindow->setLayoutParamFlags(InputWindowInfo::FLAG_NOT_TOUCH_MODAL);


        mWindowFocused = new FakeWindowHandle(application, mDispatcher, "Second",
        mFocusedWindow =
                ADISPLAY_ID_DEFAULT);
                new FakeWindowHandle(application, mDispatcher, "Second", ADISPLAY_ID_DEFAULT);
        mWindowFocused->setFrame(Rect(50, 50, 100, 100));
        mFocusedWindow->setFrame(Rect(50, 50, 100, 100));
        mWindowFocused->setLayoutParamFlags(InputWindowInfo::FLAG_NOT_TOUCH_MODAL);
        mFocusedWindow->setLayoutParamFlags(InputWindowInfo::FLAG_NOT_TOUCH_MODAL);
        mWindowFocusedTouchPoint = 60;
        mFocusedWindowTouchPoint = 60;


        // Set focused application.
        // Set focused application.
        mDispatcher->setFocusedApplication(ADISPLAY_ID_DEFAULT, application);
        mDispatcher->setFocusedApplication(ADISPLAY_ID_DEFAULT, application);
        mWindowFocused->setFocus();
        mFocusedWindow->setFocus();


        // Expect one focus window exist in display.
        // Expect one focus window exist in display.
        std::vector<sp<InputWindowHandle>> inputWindowHandles;
        mDispatcher->setInputWindows({mUnfocusedWindow, mFocusedWindow}, ADISPLAY_ID_DEFAULT);
        inputWindowHandles.push_back(mUnfocusedWindow);
        inputWindowHandles.push_back(mWindowFocused);
        mDispatcher->setInputWindows(inputWindowHandles, ADISPLAY_ID_DEFAULT);
    }
    }


    virtual void TearDown() {
    virtual void TearDown() {
        InputDispatcherTest::TearDown();
        InputDispatcherTest::TearDown();


        mUnfocusedWindow.clear();
        mUnfocusedWindow.clear();
        mWindowFocused.clear();
        mFocusedWindow.clear();
    }
    }


protected:
protected:
    sp<FakeWindowHandle> mUnfocusedWindow;
    sp<FakeWindowHandle> mUnfocusedWindow;
    sp<FakeWindowHandle> mWindowFocused;
    sp<FakeWindowHandle> mFocusedWindow;
    int32_t mWindowFocusedTouchPoint;
    int32_t mFocusedWindowTouchPoint;
};
};


// Have two windows, one with focus. Inject MotionEvent with source TOUCHSCREEN and action
// Have two windows, one with focus. Inject MotionEvent with source TOUCHSCREEN and action
@@ -1084,9 +1062,9 @@ TEST_F(InputDispatcherOnPointerDownOutsideFocus, OnPointerDownOutsideFocus_NonMo
// onPointerDownOutsideFocus callback.
// onPointerDownOutsideFocus callback.
TEST_F(InputDispatcherOnPointerDownOutsideFocus,
TEST_F(InputDispatcherOnPointerDownOutsideFocus,
        OnPointerDownOutsideFocus_OnAlreadyFocusedWindow) {
        OnPointerDownOutsideFocus_OnAlreadyFocusedWindow) {
    ASSERT_EQ(INPUT_EVENT_INJECTION_SUCCEEDED, injectMotionDown(mDispatcher,
    ASSERT_EQ(INPUT_EVENT_INJECTION_SUCCEEDED,
            AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT, mWindowFocusedTouchPoint,
              injectMotionDown(mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT,
            mWindowFocusedTouchPoint))
                               mFocusedWindowTouchPoint, mFocusedWindowTouchPoint))
            << "Inject motion event should return INPUT_EVENT_INJECTION_SUCCEEDED";
            << "Inject motion event should return INPUT_EVENT_INJECTION_SUCCEEDED";
    // Call monitor to wait for the command queue to get flushed.
    // Call monitor to wait for the command queue to get flushed.
    mDispatcher->monitor();
    mDispatcher->monitor();