Don't rely on synthetic mouse events in updateFocusChainWhenChildDie test

Synthetic mouse events are not reliable, as the platform might restrict
synthetic mouse moves. In addition, the WM might automatically activate
the window when the other window is hidden, which makes the EXPECT_FAIL
flakey.

Since the test was not written to test window activation, let's just
explicitly activate the window.

Fixes: QTBUG-23699
Change-Id: I0ac1d3bc0658dfbd600a1f5d960839860be6dd2c
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
(cherry picked from commit 2e58e242b436d0d462748546d4451f6365de4743)
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
This commit is contained in:
Tor Arne Vestbø 2022-09-14 11:14:09 +02:00
parent caa82adf07
commit b76dffec3c

View File

@ -1719,7 +1719,7 @@ void tst_QGraphicsWidget::updateFocusChainWhenChildDie()
view.resize(200, 150);
view.move(availableGeometry.topLeft() + QPoint(50, 50));
view.show();
QApplication::setActiveWindow(&view);
view.activateWindow();
QVERIFY(QTest::qWaitForWindowActive(&view));
// delete item in focus chain with no focus and verify chain
@ -1748,13 +1748,8 @@ void tst_QGraphicsWidget::updateFocusChainWhenChildDie()
w->setParentItem(parent);
//We don't crash perfect
QVERIFY(w);
const QPoint center(view.viewport()->width() / 2, view.viewport()->height() / 2);
QTest::mouseMove(view.viewport(), center);
QTest::mouseClick(view.viewport(), Qt::LeftButton, {}, center);
#ifdef Q_OS_MAC
QEXPECT_FAIL("", "QTBUG-23699", Continue);
#endif
QTRY_COMPARE(qApp->activeWindow(), static_cast<QWidget *>(&view));
view.activateWindow();
QVERIFY(QTest::qWaitForWindowActive(&view));
QTRY_COMPARE(scene.focusItem(), static_cast<QGraphicsItem *>(w));
}