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

Commit 87781efb authored by Patrick Williams's avatar Patrick Williams Committed by Automerger Merge Worker
Browse files

Merge "Use WindowInfo::transform in WindowInfosListenerTest" into udc-dev am: a1adb856

parents aef2e8d2 a1adb856
Loading
Loading
Loading
Loading
+8 −29
Original line number Original line Diff line number Diff line
@@ -25,8 +25,7 @@ using Transaction = SurfaceComposerClient::Transaction;
using gui::DisplayInfo;
using gui::DisplayInfo;
using gui::WindowInfo;
using gui::WindowInfo;


using WindowInfosPredicate =
using WindowInfosPredicate = std::function<bool(const std::vector<WindowInfo>&)>;
        std::function<bool(const std::vector<WindowInfo>&, const std::vector<DisplayInfo>&)>;


class WindowInfosListenerTest : public ::testing::Test {
class WindowInfosListenerTest : public ::testing::Test {
protected:
protected:
@@ -43,8 +42,8 @@ protected:
              : mPredicate(std::move(predicate)), mPromise(promise) {}
              : mPredicate(std::move(predicate)), mPromise(promise) {}


        void onWindowInfosChanged(const std::vector<WindowInfo>& windowInfos,
        void onWindowInfosChanged(const std::vector<WindowInfo>& windowInfos,
                                  const std::vector<DisplayInfo>& displayInfos) override {
                                  const std::vector<DisplayInfo>&) override {
            if (mPredicate(windowInfos, displayInfos)) {
            if (mPredicate(windowInfos)) {
                mPromise.set_value();
                mPromise.set_value();
            }
            }
        }
        }
@@ -77,16 +76,6 @@ const WindowInfo* findMatchingWindowInfo(const WindowInfo& targetWindowInfo,
    return nullptr;
    return nullptr;
}
}


const DisplayInfo* findMatchingDisplayInfo(int32_t displayId,
                                           const std::vector<DisplayInfo>& displayInfos) {
    for (const DisplayInfo& displayInfo : displayInfos) {
        if (displayInfo.displayId == displayId) {
            return &displayInfo;
        }
    }
    return nullptr;
}

TEST_F(WindowInfosListenerTest, WindowInfoAddedAndRemoved) {
TEST_F(WindowInfosListenerTest, WindowInfoAddedAndRemoved) {
    std::string name = "Test Layer";
    std::string name = "Test Layer";
    sp<IBinder> token = sp<BBinder>::make();
    sp<IBinder> token = sp<BBinder>::make();
@@ -104,16 +93,14 @@ TEST_F(WindowInfosListenerTest, WindowInfoAddedAndRemoved) {
            .setInputWindowInfo(surfaceControl, windowInfo)
            .setInputWindowInfo(surfaceControl, windowInfo)
            .apply();
            .apply();


    auto windowPresent = [&](const std::vector<WindowInfo>& windowInfos,
    auto windowPresent = [&](const std::vector<WindowInfo>& windowInfos) {
                             const std::vector<DisplayInfo>&) {
        return findMatchingWindowInfo(windowInfo, windowInfos);
        return findMatchingWindowInfo(windowInfo, windowInfos);
    };
    };
    ASSERT_TRUE(waitForWindowInfosPredicate(windowPresent));
    ASSERT_TRUE(waitForWindowInfosPredicate(windowPresent));


    Transaction().reparent(surfaceControl, nullptr).apply();
    Transaction().reparent(surfaceControl, nullptr).apply();


    auto windowNotPresent = [&](const std::vector<WindowInfo>& windowInfos,
    auto windowNotPresent = [&](const std::vector<WindowInfo>& windowInfos) {
                                const std::vector<DisplayInfo>&) {
        return !findMatchingWindowInfo(windowInfo, windowInfos);
        return !findMatchingWindowInfo(windowInfo, windowInfos);
    };
    };
    ASSERT_TRUE(waitForWindowInfosPredicate(windowNotPresent));
    ASSERT_TRUE(waitForWindowInfosPredicate(windowNotPresent));
@@ -137,8 +124,7 @@ TEST_F(WindowInfosListenerTest, WindowInfoChanged) {
            .setInputWindowInfo(surfaceControl, windowInfo)
            .setInputWindowInfo(surfaceControl, windowInfo)
            .apply();
            .apply();


    auto windowIsPresentAndTouchableRegionEmpty = [&](const std::vector<WindowInfo>& windowInfos,
    auto windowIsPresentAndTouchableRegionEmpty = [&](const std::vector<WindowInfo>& windowInfos) {
                                                      const std::vector<DisplayInfo>&) {
        auto foundWindowInfo = findMatchingWindowInfo(windowInfo, windowInfos);
        auto foundWindowInfo = findMatchingWindowInfo(windowInfo, windowInfos);
        if (!foundWindowInfo) {
        if (!foundWindowInfo) {
            return false;
            return false;
@@ -151,21 +137,14 @@ TEST_F(WindowInfosListenerTest, WindowInfoChanged) {
    Transaction().setInputWindowInfo(surfaceControl, windowInfo).apply();
    Transaction().setInputWindowInfo(surfaceControl, windowInfo).apply();


    auto windowIsPresentAndTouchableRegionMatches =
    auto windowIsPresentAndTouchableRegionMatches =
            [&](const std::vector<WindowInfo>& windowInfos,
            [&](const std::vector<WindowInfo>& windowInfos) {
                const std::vector<DisplayInfo>& displayInfos) {
                auto foundWindowInfo = findMatchingWindowInfo(windowInfo, windowInfos);
                auto foundWindowInfo = findMatchingWindowInfo(windowInfo, windowInfos);
                if (!foundWindowInfo) {
                if (!foundWindowInfo) {
                    return false;
                    return false;
                }
                }


                auto displayInfo =
                        findMatchingDisplayInfo(foundWindowInfo->displayId, displayInfos);
                if (!displayInfo) {
                    return false;
                }

                auto touchableRegion =
                auto touchableRegion =
                        displayInfo->transform.transform(foundWindowInfo->touchableRegion);
                        foundWindowInfo->transform.transform(foundWindowInfo->touchableRegion);
                return touchableRegion.hasSameRects(windowInfo.touchableRegion);
                return touchableRegion.hasSameRects(windowInfo.touchableRegion);
            };
            };
    ASSERT_TRUE(waitForWindowInfosPredicate(windowIsPresentAndTouchableRegionMatches));
    ASSERT_TRUE(waitForWindowInfosPredicate(windowIsPresentAndTouchableRegionMatches));