From 5c6f8b2c67852dbd3674658736d1a1ab96a2571d Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Wed, 2 Feb 2022 16:10:35 +0100 Subject: [PATCH] Always wait in the QScreen::grabWindow test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On X11 we already had to wait as window managers might scroll windows in. On macOS we also waited - albeit a bit shorter - also because screens scroll in slowly. We didn't wait on Windows, and on Windows the test is quite flaky. Attempting to make it run stably by waiting for long enough so that all paint events are flushed to the screen. As a drive-by, break some overly long lines. Task-number: QTBUG-100412 Pick-to: 6.3 Change-Id: I49b1e447aced2fe1af3c5d30b514f8df3cc1813c Reviewed-by: Tor Arne Vestbø --- tests/auto/gui/kernel/qscreen/tst_qscreen.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/tests/auto/gui/kernel/qscreen/tst_qscreen.cpp b/tests/auto/gui/kernel/qscreen/tst_qscreen.cpp index a6e9535e889..18120e8c24f 100644 --- a/tests/auto/gui/kernel/qscreen/tst_qscreen.cpp +++ b/tests/auto/gui/kernel/qscreen/tst_qscreen.cpp @@ -283,13 +283,12 @@ void tst_QScreen::grabWindow() if (!QTest::qWaitForWindowExposed(&window)) QSKIP("Failed to expose window - aborting"); - if (QGuiApplication::platformName().startsWith(QLatin1String("xcb"), Qt::CaseInsensitive)) - QTest::qWait(1500); // this is ridiculously necessary because of effects combined with slowness of VMs -#ifdef Q_OS_MACOS // wait for desktop on screen to scroll into place - QTest::qWait(1000); -#endif + // this is necessary because of scrolling effects combined with potential slowness of VMs + QTest::qWait(1500); - QSize expectedGrabSize = grabRect.isValid() ? grabRect.size() : (grabWindow ? windowRect.size() : screen->size()); + QSize expectedGrabSize = grabRect.isValid() + ? grabRect.size() + : (grabWindow ? windowRect.size() : screen->size()); // we ask for pixel coordinates, but will get a pixmap with device-specific DPR expectedGrabSize *= screen->devicePixelRatio(); @@ -297,7 +296,9 @@ void tst_QScreen::grabWindow() QImage paintedImage = window.image; QCOMPARE(paintedImage.devicePixelRatio(), screenDpr); - const QPixmap pixmap = screen->grabWindow(grabWindow ? window.winId() : 0, grabRect.x(), grabRect.y(), grabRect.width(), grabRect.height()); + const QPixmap pixmap = screen->grabWindow(grabWindow + ? window.winId() + : 0, grabRect.x(), grabRect.y(), grabRect.width(), grabRect.height()); QImage grabbedImage = pixmap.toImage(); const QSize grabbedSize = grabbedImage.size();