diff options
author | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2021-10-25 12:30:32 +0200 |
---|---|---|
committer | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2021-10-27 20:08:33 +0200 |
commit | 05532a09684990ebfabf1fa60fcdb7751afb8282 (patch) | |
tree | f420c0b2e01b58a5b06bcab5ef86ec64f2f17bf1 /tests | |
parent | 5ffc744b791a114a3180a425dd26e298f7399955 (diff) |
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 <richard.gustavsen@qt.io>
Reviewed-by: Doris Verria <doris.verria@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/widgets/widgets/qtabbar/tst_qtabbar.cpp | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/tests/auto/widgets/widgets/qtabbar/tst_qtabbar.cpp b/tests/auto/widgets/widgets/qtabbar/tst_qtabbar.cpp index b1b42c0018..66e7326a06 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<QPaintEvent *>(event)->rect())) + if (event->type() == QEvent::Paint && + static_cast<QPaintEvent *>(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(); + repaintChecker.rectToBeRepainted = tabRect; + // if a press repaints the tab... QTest::mousePress(&tabBar, Qt::LeftButton, {}, tabCenter); - QTest::mouseEvent(QTest::MouseMove, &tabBar, Qt::LeftButton, {}, tabCenter + QPoint(tabCenter.x(), tabCenter.y() + tabRect.height())); + const bool pressRepainted = QTest::qWaitFor([&]{ return repaintChecker.repainted; }, 250); - // make sure the holding tab is repainted after releasing the mouse + // ... then releasing the mouse outside the tabbar should repaint it as well repaintChecker.repainted = false; - repaintChecker.rectToBeRepainted = tabRect; 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<int> &positions) |