Make QMainWindow::restoreStateSizeChanged test less time sensitive

Amends 32edae5e26, which introduced a
timeout after which the restored state is discarded. If this timeout
hits during a CI run, then the test is expected to
fail.

Implement a lambda that watches for the restored state to disappear.

This happens primarily when restoring a fullscreen state, where some
desktop environments scroll in a new virtual desktop. It should not
happen for other data tags.

Change-Id: I5ff43a4e1857eca17a5d4fe2b47add1f70636e8d
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Reviewed-by: Jan Arve Sæther <jan-arve.saether@qt.io>
This commit is contained in:
Volker Hilsheimer 2021-10-18 16:34:09 +02:00
parent c58a3a4aae
commit a3c8518268

View File

@ -1443,6 +1443,8 @@ void tst_QMainWindow::restoreStateSizeChanged()
auto mainWindow = QScopedPointer<QMainWindow>(createMainWindow());
mainWindow->restoreGeometry(geometryData);
QElapsedTimer timer;
timer.start();
mainWindow->restoreState(stateData);
mainWindow->setWindowState(showState);
mainWindow->show();
@ -1451,8 +1453,33 @@ void tst_QMainWindow::restoreStateSizeChanged()
QDockWidget *dockWidget = mainWindow->findChild<QDockWidget*>("Dock Widget");
QVERIFY(dockWidget);
QCOMPARE(mainWindow->normalGeometry().size(), normalGeometry.size());
if (sameSize)
QTRY_COMPARE(dockWidget->width(), dockWidgetWidth);
if (sameSize) {
// The implementation discards the restored state 150ms after a resize
// event. If it takes too long to get here, then the test cannot pass anymore
// and we want to XFAIL rather then skip it with some information that might
// help us adjust the timeout in QMainWindowLayout.
bool expectFail = false;
const auto waitForLastResize = [&]() -> bool {
if (dockWidget->width() == dockWidgetWidth)
return true;
if (timer.elapsed() > 150) {
QMainWindowLayout *l = mainWindow->findChild<QMainWindowLayout *>();
Q_ASSERT(l);
if (!l->restoredState) {
qWarning("Restored state discarded after %lld", timer.elapsed());
expectFail = true;
return true;
}
}
return false;
};
QTRY_VERIFY_WITH_TIMEOUT(waitForLastResize(), 500);
if (expectFail) {
QEXPECT_FAIL("fullscreen", "Restored state probably discarded too early", Continue);
QEXPECT_FAIL("maximized->fullscreen", "Restored state probably discarded too early", Continue);
}
QCOMPARE(dockWidget->width(), dockWidgetWidth);
}
}
void tst_QMainWindow::createPopupMenu()