Always wait in the QScreen::grabWindow test

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ø <tor.arne.vestbo@qt.io>
This commit is contained in:
Volker Hilsheimer 2022-02-02 16:10:35 +01:00
parent c7a52d9d54
commit 5c6f8b2c67

View File

@ -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();