summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVolker Hilsheimer <volker.hilsheimer@qt.io>2021-10-18 16:34:09 +0200
committerVolker Hilsheimer <volker.hilsheimer@qt.io>2021-10-20 18:05:15 +0200
commita3c85182682c3dd2b220198f8bd8bc8c593f0f9e (patch)
tree8ca92bf716d240ea19f0802d7efb8f72a9d1b1d0
parentc58a3a4aae4c423bd0477a981ad1c517a30579e3 (diff)
Make QMainWindow::restoreStateSizeChanged test less time sensitive
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 <Friedemann.Kleint@qt.io> Reviewed-by: Jan Arve Sæther <jan-arve.saether@qt.io>
-rw-r--r--tests/auto/widgets/widgets/qmainwindow/tst_qmainwindow.cpp31
1 files 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<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()