From a3c85182682c3dd2b220198f8bd8bc8c593f0f9e Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Mon, 18 Oct 2021 16:34:09 +0200 Subject: [PATCH] Make QMainWindow::restoreStateSizeChanged test less time sensitive MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Amends 32edae5e268b968aff82f0713612eff2feffb4e1, 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 Reviewed-by: Jan Arve Sæther --- .../widgets/qmainwindow/tst_qmainwindow.cpp | 31 +++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/tests/auto/widgets/widgets/qmainwindow/tst_qmainwindow.cpp b/tests/auto/widgets/widgets/qmainwindow/tst_qmainwindow.cpp index e30df32d5d..0eb59fbce6 100644 --- a/tests/auto/widgets/widgets/qmainwindow/tst_qmainwindow.cpp +++ b/tests/auto/widgets/widgets/qmainwindow/tst_qmainwindow.cpp @@ -1443,6 +1443,8 @@ void tst_QMainWindow::restoreStateSizeChanged() auto mainWindow = QScopedPointer(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("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(); + 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()