From 05532a09684990ebfabf1fa60fcdb7751afb8282 Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Mon, 25 Oct 2021 12:30:32 +0200 Subject: [PATCH] Fix test to not rely on event processing QTest's simulation of mouse move events currently uses QCursor::setPos and then processes events. This is unreliable across platforms. This test relies on the event processing and either way has inverted logic in the paint event; the painted region needs to at least include the tab's rect, not the other way around. Also, the mouse move wasn't needed here at all, and some styles don't have a different style for pressed tabs anyway. Pick-to: 6.2 Change-Id: Ib8f6f7be017ff87458e96ec419edcd065dd75b15 Reviewed-by: Richard Moe Gustavsen Reviewed-by: Doris Verria Reviewed-by: Qt CI Bot --- .../widgets/widgets/qtabbar/tst_qtabbar.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/tests/auto/widgets/widgets/qtabbar/tst_qtabbar.cpp b/tests/auto/widgets/widgets/qtabbar/tst_qtabbar.cpp index b1b42c00187..66e7326a062 100644 --- a/tests/auto/widgets/widgets/qtabbar/tst_qtabbar.cpp +++ b/tests/auto/widgets/widgets/qtabbar/tst_qtabbar.cpp @@ -842,9 +842,10 @@ void tst_QTabBar::mouseReleaseOutsideTabBar() QRect rectToBeRepainted; bool eventFilter(QObject *, QEvent *event) override { - if (event->type() == QEvent::Paint - && rectToBeRepainted.contains(static_cast(event)->rect())) + if (event->type() == QEvent::Paint && + static_cast(event)->rect().contains(rectToBeRepainted)) { repainted = true; + } return false; } } repaintChecker; @@ -859,14 +860,15 @@ void tst_QTabBar::mouseReleaseOutsideTabBar() QRect tabRect = tabBar.tabRect(1); QPoint tabCenter = tabRect.center(); - QTest::mousePress(&tabBar, Qt::LeftButton, {}, tabCenter); - QTest::mouseEvent(QTest::MouseMove, &tabBar, Qt::LeftButton, {}, tabCenter + QPoint(tabCenter.x(), tabCenter.y() + tabRect.height())); - - // make sure the holding tab is repainted after releasing the mouse - repaintChecker.repainted = false; repaintChecker.rectToBeRepainted = tabRect; + // if a press repaints the tab... + QTest::mousePress(&tabBar, Qt::LeftButton, {}, tabCenter); + const bool pressRepainted = QTest::qWaitFor([&]{ return repaintChecker.repainted; }, 250); + + // ... then releasing the mouse outside the tabbar should repaint it as well + repaintChecker.repainted = false; QTest::mouseRelease(&tabBar, Qt::LeftButton, {}, tabCenter + QPoint(tabCenter.x(), tabCenter.y() + tabRect.height())); - QTRY_VERIFY(repaintChecker.repainted); + QTRY_COMPARE(repaintChecker.repainted, pressRepainted); } void tst_QTabBar::checkPositions(const TabBar &tabbar, const QList &positions)