diff --git a/tests/auto/widgets/kernel/qwidget/BLACKLIST b/tests/auto/widgets/kernel/qwidget/BLACKLIST index 254ca784ab..880ec6f9b4 100644 --- a/tests/auto/widgets/kernel/qwidget/BLACKLIST +++ b/tests/auto/widgets/kernel/qwidget/BLACKLIST @@ -12,8 +12,6 @@ ubuntu opensuse-leap # QTBUG-68175 opensuse-42.3 -[childEvents] -macos [renderInvisible] macos [optimizedResizeMove] @@ -24,8 +22,6 @@ osx macos arm [render_systemClip] osx -[showMinimizedKeepsFocus] -macos [maskedUpdate] opensuse opensuse-leap @@ -38,11 +34,6 @@ opensuse-leap ubuntu sles-15 -[syntheticEnterLeave] -macos # Can't move cursor (QTBUG-76312) -[taskQTBUG_4055_sendSyntheticEnterLeave] -macos # Can't move cursor (QTBUG-76312) - # QTBUG-87668 [reparent] android diff --git a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp index 8acba6748c..3f51938ce1 100644 --- a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp +++ b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp @@ -296,6 +296,8 @@ private slots: void childEvents(); void render(); + void renderChildFillsBackground(); + void renderTargetOffset(); void renderInvisible(); void renderWithPainter(); void render_task188133(); @@ -435,8 +437,6 @@ private slots: void setParentChangesFocus(); private: - bool ensureScreenSize(int width, int height); - const QString m_platform; QSize m_testWidgetSize; QPoint m_availableTopLeft; @@ -446,12 +446,6 @@ private: const int m_fuzz; }; -bool tst_QWidget::ensureScreenSize(int width, int height) -{ - const QSize available = QGuiApplication::primaryScreen()->availableGeometry().size(); - return (available.width() >= width && available.height() >= height); -} - // Testing get/set functions void tst_QWidget::getSetCheck() { @@ -466,18 +460,24 @@ void tst_QWidget::getSetCheck() QVERIFY(var1.data() != obj1.style()); QVERIFY(obj1.style() != nullptr); // style can never be 0 for a widget + const QRegularExpression negativeNotPossible(u"^.*Negative sizes \\(.*\\) are not possible$"_qs); + const QRegularExpression largestAllowedSize(u"^.*The largest allowed size is \\(.*\\)$"_qs); // int QWidget::minimumWidth() // void QWidget::setMinimumWidth(int) obj1.setMinimumWidth(0); QCOMPARE(obj1.minimumWidth(), 0); + QTest::ignoreMessage(QtWarningMsg, negativeNotPossible); obj1.setMinimumWidth(INT_MIN); QCOMPARE(obj1.minimumWidth(), 0); // A widgets width can never be less than 0 + QTest::ignoreMessage(QtWarningMsg, largestAllowedSize); obj1.setMinimumWidth(INT_MAX); child1.setMinimumWidth(0); QCOMPARE(child1.minimumWidth(), 0); + QTest::ignoreMessage(QtWarningMsg, negativeNotPossible); child1.setMinimumWidth(INT_MIN); QCOMPARE(child1.minimumWidth(), 0); // A widgets width can never be less than 0 + QTest::ignoreMessage(QtWarningMsg, largestAllowedSize); child1.setMinimumWidth(INT_MAX); QCOMPARE(child1.minimumWidth(), QWIDGETSIZE_MAX); // The largest minimum size should only be as big as the maximium @@ -485,14 +485,18 @@ void tst_QWidget::getSetCheck() // void QWidget::setMinimumHeight(int) obj1.setMinimumHeight(0); QCOMPARE(obj1.minimumHeight(), 0); + QTest::ignoreMessage(QtWarningMsg, negativeNotPossible); obj1.setMinimumHeight(INT_MIN); QCOMPARE(obj1.minimumHeight(), 0); // A widgets height can never be less than 0 + QTest::ignoreMessage(QtWarningMsg, largestAllowedSize); obj1.setMinimumHeight(INT_MAX); child1.setMinimumHeight(0); QCOMPARE(child1.minimumHeight(), 0); + QTest::ignoreMessage(QtWarningMsg, negativeNotPossible); child1.setMinimumHeight(INT_MIN); QCOMPARE(child1.minimumHeight(), 0); // A widgets height can never be less than 0 + QTest::ignoreMessage(QtWarningMsg, largestAllowedSize); child1.setMinimumHeight(INT_MAX); QCOMPARE(child1.minimumHeight(), QWIDGETSIZE_MAX); // The largest minimum size should only be as big as the maximium @@ -500,8 +504,10 @@ void tst_QWidget::getSetCheck() // void QWidget::setMaximumWidth(int) obj1.setMaximumWidth(0); QCOMPARE(obj1.maximumWidth(), 0); + QTest::ignoreMessage(QtWarningMsg, negativeNotPossible); obj1.setMaximumWidth(INT_MIN); QCOMPARE(obj1.maximumWidth(), 0); // A widgets width can never be less than 0 + QTest::ignoreMessage(QtWarningMsg, largestAllowedSize); obj1.setMaximumWidth(INT_MAX); QCOMPARE(obj1.maximumWidth(), QWIDGETSIZE_MAX); // QWIDGETSIZE_MAX is the abs max, not INT_MAX @@ -509,8 +515,10 @@ void tst_QWidget::getSetCheck() // void QWidget::setMaximumHeight(int) obj1.setMaximumHeight(0); QCOMPARE(obj1.maximumHeight(), 0); + QTest::ignoreMessage(QtWarningMsg, negativeNotPossible); obj1.setMaximumHeight(INT_MIN); QCOMPARE(obj1.maximumHeight(), 0); // A widgets height can never be less than 0 + QTest::ignoreMessage(QtWarningMsg, largestAllowedSize); obj1.setMaximumHeight(INT_MAX); QCOMPARE(obj1.maximumHeight(), QWIDGETSIZE_MAX); // QWIDGETSIZE_MAX is the abs max, not INT_MAX @@ -570,6 +578,7 @@ void tst_QWidget::getSetCheck() QBoxLayout *var11 = new QBoxLayout(QBoxLayout::LeftToRight); obj1.setLayout(var11); QCOMPARE(static_cast(var11), obj1.layout()); + QTest::ignoreMessage(QtWarningMsg, "QWidget::setLayout: Cannot set layout to 0"); obj1.setLayout(nullptr); QCOMPARE(static_cast(var11), obj1.layout()); // You cannot set a 0-pointer layout, that keeps the current delete var11; // This will remove the layout from the widget @@ -1240,6 +1249,8 @@ void tst_QWidget::ignoreKeyEventsWhenDisabled_QTBUG27417() centerOnScreen(&lineEdit); lineEdit.setDisabled(true); lineEdit.show(); + QTest::ignoreMessage(QtWarningMsg, "Keyboard event not accepted by receiving widget"); + QTest::ignoreMessage(QtWarningMsg, "Keyboard event not accepted by receiving widget"); QTest::keyClick(&lineEdit, Qt::Key_A); QTRY_VERIFY(lineEdit.text().isEmpty()); } @@ -3261,9 +3272,8 @@ void tst_QWidget::setGeometry() tlw.setWindowTitle(QLatin1String(QTest::currentTestFunction())); QWidget child(&tlw); - const QPoint topLeft = QGuiApplication::primaryScreen()->availableGeometry().topLeft(); const QSize initialSize = 2 * m_testWidgetSize; - QRect tr(topLeft + QPoint(100,100), initialSize); + QRect tr(m_availableTopLeft + QPoint(100,100), initialSize); QRect cr(50,50,50,50); tlw.setGeometry(tr); child.setGeometry(cr); @@ -3272,15 +3282,14 @@ void tst_QWidget::setGeometry() QCOMPARE(child.geometry(), cr); tlw.setParent(nullptr, Qt::Window|Qt::FramelessWindowHint); - tr = QRect(topLeft, initialSize / 2); + tr = QRect(m_availableTopLeft, initialSize / 2); tlw.setGeometry(tr); QCOMPARE(tlw.geometry(), tr); tlw.showNormal(); - QTest::qWait(50); - if (tlw.frameGeometry() != tlw.geometry()) + if (!QTest::qWaitFor([&tlw]{ return tlw.frameGeometry() == tlw.geometry(); })) QSKIP("Your window manager is too broken for this test"); - if (m_platform == QStringLiteral("xcb")) - QSKIP("QTBUG-26424"); + if (m_platform == QStringLiteral("xcb") && tlw.geometry() != tr) + QEXPECT_FAIL("", "QTBUG-26424", Continue); QCOMPARE(tlw.geometry(), tr); } @@ -5162,7 +5171,7 @@ void tst_QWidget::scroll() UpdateWidget updateWidget; updateWidget.resize(w, h); updateWidget.reset(); - updateWidget.move(QGuiApplication::primaryScreen()->geometry().center() - QPoint(250, 250)); + updateWidget.move(m_availableTopLeft); updateWidget.showNormal(); QApplication::setActiveWindow(&updateWidget); QVERIFY(QTest::qWaitForWindowActive(&updateWidget)); @@ -5812,8 +5821,7 @@ void tst_QWidget::moveChild() parent.setStyle(style.data()); ColorWidget child(&parent, Qt::Widget, Qt::blue); - parent.setGeometry(QRect(parent.screen()->availableGeometry().topLeft() + QPoint(50, 50), - QSize(200, 200))); + parent.setGeometry(QRect(m_availableTopLeft + QPoint(50, 50), QSize(200, 200))); child.setGeometry(25, 25, 50, 50); #ifndef QT_NO_CURSOR // Try to make sure the cursor is not in a taskbar area to prevent tooltips or window highlighting QCursor::setPos(parent.geometry().topRight() + QPoint(50 , 50)); @@ -5849,10 +5857,10 @@ void tst_QWidget::moveChild() QTRY_COMPARE(pos, child.pos()); QTRY_COMPARE(parent.r, QRegion(oldGeometry) - child.geometry()); -#if !defined(Q_OS_MACOS) + if (QGuiApplication::platformName() == "cocoa") + QEXPECT_FAIL("", "Cocoa backing store doesn't implement scroll", Abort); // should be scrolled in backingstore QCOMPARE(child.r, QRegion()); -#endif VERIFY_COLOR(child, child.rect(), child.color); VERIFY_COLOR(parent, QRegion(parent.rect()) - child.geometry(), parent.color); } @@ -6484,6 +6492,9 @@ void tst_QWidget::setToolTip() QCOMPARE(widget.toolTip(), QString()); QCOMPARE(spy.count(), 2); + const int wakeUpDelay = widget.style()->styleHint(QStyle::SH_ToolTip_WakeUpDelay); + const int fallAsleepDelay = widget.style()->styleHint(QStyle::SH_ToolTip_FallAsleepDelay); + for (int pass = 0; pass < 2; ++pass) { QCursor::setPos(m_safeCursorPos); QScopedPointer popup(new QWidget(nullptr, Qt::Popup)); @@ -6503,12 +6514,12 @@ void tst_QWidget::setToolTip() QWindow *popupWindow = popup->windowHandle(); QTest::qWait(10); QTest::mouseMove(popupWindow, QPoint(25, 25)); - QTest::qWait(900); // delay is 700 + QTest::qWait(wakeUpDelay + 200); QCOMPARE(spy1.count(), 1); QCOMPARE(spy2.count(), 0); if (pass == 0) - QTest::qWait(2200); // delay is 2000 + QTest::qWait(fallAsleepDelay + 200); QTest::mouseMove(popupWindow); } @@ -6763,7 +6774,6 @@ void tst_QWidget::clean_qt_x11_enforce_cursor() QTest::qWait(100); child->setFocus(); - QApplication::processEvents(); QTest::qWait(100); delete w; @@ -6799,8 +6809,19 @@ public: bool eventFilter(QObject *object, QEvent *event) override { QWidget *widget = qobject_cast(object); - if (widget && !event->spontaneous()) - events.append(qMakePair(widget, event->type())); + if (widget && !event->spontaneous()) { + switch (event->type()) { + // we might get those events if we couldn't move the cursor + case QEvent::Enter: + case QEvent::Leave: + // we might get this on systems that have an input method installed + case QEvent::InputMethodQuery: + break; + default: + events.append(qMakePair(widget, event->type())); + break; + } + } return false; } @@ -6842,11 +6863,6 @@ void tst_QWidget::childEvents() { EventRecorder::EventList expected; - // Move away the cursor; otherwise it might result in an enter event if it's - // inside the widget when the widget is shown. - QCursor::setPos(m_safeCursorPos); - QTest::qWait(100); - { // no children created, not shown QWidget widget; @@ -7122,7 +7138,6 @@ private: void tst_QWidget::render() { - return; QCalendarWidget source; source.setWindowTitle(QLatin1String(QTest::currentTestFunction())); // disable anti-aliasing to eliminate potential differences when subpixel antialiasing @@ -7137,16 +7152,11 @@ void tst_QWidget::render() RenderWidget target(&source); target.resize(source.size()); target.show(); - - QCoreApplication::processEvents(); - QCoreApplication::sendPostedEvents(); - QTest::qWait(250); + QVERIFY(QTest::qWaitForWindowExposed(&target)); const QImage sourceImage = source.grab(QRect(QPoint(0, 0), QSize(-1, -1))).toImage(); - QCoreApplication::processEvents(); QImage targetImage = target.grab(QRect(QPoint(0, 0), QSize(-1, -1))).toImage(); - QCoreApplication::processEvents(); - QCOMPARE(sourceImage, targetImage); + QTRY_COMPARE(sourceImage, targetImage); // Fill target.rect() will Qt::red and render // QRegion(0, 0, source->width(), source->height() / 2, QRegion::Ellipse) @@ -7159,55 +7169,60 @@ void tst_QWidget::render() QVERIFY(sourceImage != targetImage); QCOMPARE(targetImage.pixel(target.width() / 2, 29), QColor(Qt::red).rgb()); + if (targetImage.devicePixelRatioF() > 1) + QEXPECT_FAIL("", "This test fails on high-DPI displays", Continue); QCOMPARE(targetImage.pixel(target.width() / 2, 30), sourceImage.pixel(source.width() / 2, 0)); +} - // Test that a child widget properly fills its background - { - QWidget window; - window.setWindowTitle(QLatin1String(QTest::currentTestFunction())); - window.resize(100, 100); - // prevent custom styles - window.setStyle(QStyleFactory::create(QLatin1String("Windows"))); - window.show(); - QVERIFY(QTest::qWaitForWindowExposed(&window)); - QWidget child(&window); - child.resize(window.size()); - child.show(); +// Test that a child widget properly fills its background +void tst_QWidget::renderChildFillsBackground() +{ + QWidget window; + window.setWindowTitle(QLatin1String(QTest::currentTestFunction())); + window.resize(100, 100); + // prevent custom styles + window.setStyle(QStyleFactory::create(QLatin1String("Windows"))); + window.show(); + QVERIFY(QTest::qWaitForWindowExposed(&window)); + QWidget child(&window); + child.resize(window.size()); + child.show(); - QCoreApplication::processEvents(); - const QPixmap childPixmap = child.grab(QRect(QPoint(0, 0), QSize(-1, -1))); - const QPixmap windowPixmap = window.grab(QRect(QPoint(0, 0), QSize(-1, -1))); - QCOMPARE(childPixmap, windowPixmap); - } + QCoreApplication::processEvents(); + const QPixmap childPixmap = child.grab(QRect(QPoint(0, 0), QSize(-1, -1))); + const QPixmap windowPixmap = window.grab(QRect(QPoint(0, 0), QSize(-1, -1))); + QEXPECT_FAIL("", "This test fails on all platforms", Continue); + QCOMPARE(childPixmap, windowPixmap); +} - { // Check that the target offset is correct. - QWidget widget; - widget.setWindowTitle(QLatin1String(QTest::currentTestFunction())); - widget.resize(200, 200); - widget.setAutoFillBackground(true); - widget.setPalette(Qt::red); - // prevent custom styles - widget.setStyle(QStyleFactory::create(QLatin1String("Windows"))); - widget.show(); - QVERIFY(QTest::qWaitForWindowExposed(&widget)); - QImage image(widget.size(), QImage::Format_RGB32); - image.fill(QColor(Qt::blue).rgb()); +void tst_QWidget::renderTargetOffset() +{ // Check that the target offset is correct. + QWidget widget; + widget.setWindowTitle(QLatin1String(QTest::currentTestFunction())); + widget.resize(200, 200); + widget.setAutoFillBackground(true); + widget.setPalette(Qt::red); + // prevent custom styles + widget.setStyle(QStyleFactory::create(QLatin1String("Windows"))); + widget.show(); + QVERIFY(QTest::qWaitForWindowExposed(&widget)); + QImage image(widget.size(), QImage::Format_RGB32); + image.fill(QColor(Qt::blue).rgb()); - // Target offset (0, 0) - widget.render(&image, QPoint(), QRect(20, 20, 100, 100)); - QCOMPARE(image.pixel(0, 0), QColor(Qt::red).rgb()); - QCOMPARE(image.pixel(99, 99), QColor(Qt::red).rgb()); - QCOMPARE(image.pixel(100, 100), QColor(Qt::blue).rgb()); + // Target offset (0, 0) + widget.render(&image, QPoint(), QRect(20, 20, 100, 100)); + QCOMPARE(image.pixel(0, 0), QColor(Qt::red).rgb()); + QCOMPARE(image.pixel(99, 99), QColor(Qt::red).rgb()); + QCOMPARE(image.pixel(100, 100), QColor(Qt::blue).rgb()); - // Target offset (20, 20). - image.fill(QColor(Qt::blue).rgb()); - widget.render(&image, QPoint(20, 20), QRect(20, 20, 100, 100)); - QCOMPARE(image.pixel(0, 0), QColor(Qt::blue).rgb()); - QCOMPARE(image.pixel(19, 19), QColor(Qt::blue).rgb()); - QCOMPARE(image.pixel(20, 20), QColor(Qt::red).rgb()); - QCOMPARE(image.pixel(119, 119), QColor(Qt::red).rgb()); - QCOMPARE(image.pixel(120, 120), QColor(Qt::blue).rgb()); - } + // Target offset (20, 20). + image.fill(QColor(Qt::blue).rgb()); + widget.render(&image, QPoint(20, 20), QRect(20, 20, 100, 100)); + QCOMPARE(image.pixel(0, 0), QColor(Qt::blue).rgb()); + QCOMPARE(image.pixel(19, 19), QColor(Qt::blue).rgb()); + QCOMPARE(image.pixel(20, 20), QColor(Qt::red).rgb()); + QCOMPARE(image.pixel(119, 119), QColor(Qt::red).rgb()); + QCOMPARE(image.pixel(120, 120), QColor(Qt::blue).rgb()); } // On Windows the active palette is used instead of the inactive palette even @@ -7256,8 +7271,6 @@ void tst_QWidget::renderInvisible() dummyFocusWidget.move(calendar->geometry().bottomLeft() + QPoint(0, 100)); dummyFocusWidget.show(); QVERIFY(QTest::qWaitForWindowExposed(&dummyFocusWidget)); - QCoreApplication::processEvents(); - QTest::qWait(120); // Create normal reference image. const QSize calendarSize = calendar->size(); @@ -7271,7 +7284,6 @@ void tst_QWidget::renderInvisible() // Create resized reference image. const QSize calendarSizeResized = calendar->size() + QSize(50, 50); calendar->resize(calendarSizeResized); - QCoreApplication::processEvents(); QTest::qWait(30); QImage referenceImageResized(calendarSizeResized, QImage::Format_ARGB32); calendar->render(&referenceImageResized); @@ -7282,7 +7294,6 @@ void tst_QWidget::renderInvisible() // Explicitly hide the calendar. calendar->hide(); - QCoreApplication::processEvents(); QTest::qWait(30); workaroundPaletteIssue(calendar.data()); @@ -7312,7 +7323,6 @@ void tst_QWidget::renderInvisible() } calendar->hide(); - QCoreApplication::processEvents(); QTest::qWait(30); { // Calendar explicitly hidden. @@ -7380,7 +7390,6 @@ void tst_QWidget::renderInvisible() // Navigation bar isn't explicitly hidden anymore. navigationBar->show(); - QCoreApplication::processEvents(); QTest::qWait(30); QVERIFY(!calendar->isVisible()); @@ -8091,7 +8100,7 @@ void tst_QWidget::moveWindowInShowEvent_data() QTest::addColumn("initial"); QTest::addColumn("position"); - QPoint p = QGuiApplication::primaryScreen()->availableGeometry().topLeft(); + QPoint p = m_availableTopLeft; QTest::newRow("1") << p << (p + QPoint(10, 10)); QTest::newRow("2") << (p + QPoint(10,10)) << p; @@ -8128,21 +8137,15 @@ void tst_QWidget::moveWindowInShowEvent() // show it widget.showNormal(); QVERIFY(QTest::qWaitForWindowExposed(&widget)); - QTest::qWait(100); // it should have moved QCOMPARE(widget.pos(), position); } void tst_QWidget::repaintWhenChildDeleted() { -#ifdef Q_OS_WIN - QTest::qWait(1000); -#endif ColorWidget w(nullptr, Qt::FramelessWindowHint, Qt::red); w.setWindowTitle(QLatin1String(QTest::currentTestFunction())); - QPoint startPoint = w.screen()->availableGeometry().topLeft(); - startPoint.rx() += 50; - startPoint.ry() += 50; + const QPoint startPoint = m_availableTopLeft + QPoint(50, 50); w.setGeometry(QRect(startPoint, QSize(100, 100))); w.show(); QVERIFY(QTest::qWaitForWindowExposed(&w)); @@ -8165,9 +8168,7 @@ void tst_QWidget::hideOpaqueChildWhileHidden() { ColorWidget w(nullptr, Qt::FramelessWindowHint, Qt::red); w.setWindowTitle(QLatin1String(QTest::currentTestFunction())); - QPoint startPoint = w.screen()->availableGeometry().topLeft(); - startPoint.rx() += 50; - startPoint.ry() += 50; + const QPoint startPoint = m_availableTopLeft + QPoint(50, 50); w.setGeometry(QRect(startPoint, QSize(100, 100))); ColorWidget child(&w, Qt::Widget, Qt::blue); @@ -8243,7 +8244,8 @@ void tst_QWidget::updateWhileMinimized() qDebug() << "xcb: XDG_CURRENT_DESKTOP=" << desktop; if (desktop == QStringLiteral("ubuntu:GNOME") || desktop == QStringLiteral("GNOME-Classic:GNOME") - || desktop == QStringLiteral("GNOME")) + || desktop == QStringLiteral("GNOME") + || desktop.isEmpty()) // on local VMs count = 1; } QCOMPARE(widget.numPaintEvents, count); @@ -8892,6 +8894,8 @@ public: paintedRegion += event->region(); for (const QRect &r : event->region()) p.fillRect(r, Qt::red); + + repainted = true; } void resizeEvent(QResizeEvent *) override @@ -8900,6 +8904,7 @@ public: } QRegion paintedRegion; + bool repainted = false; public slots: void resizeDown() { setGeometry(QRect(0, 50, 50, 50)); } @@ -8926,19 +8931,19 @@ void tst_QWidget::setMaskInResizeEvent() w.reset(); testWidget.paintedRegion = QRegion(); - QTimer::singleShot(0, &testWidget, SLOT(resizeDown())); - QTest::qWait(100); + testWidget.resizeDown(); QRegion expectedParentUpdate(0, 0, 100, 10); // Old testWidget area. expectedParentUpdate += testWidget.geometry(); // New testWidget area. + QTRY_VERIFY(testWidget.repainted); QTRY_COMPARE(w.paintedRegion, expectedParentUpdate); QTRY_COMPARE(testWidget.paintedRegion, testWidget.mask()); testWidget.paintedRegion = QRegion(); - // Now resize the widget again, but in the oposite direction - QTimer::singleShot(0, &testWidget, SLOT(resizeUp())); - QTest::qWait(100); - + testWidget.repainted = false; + // Now resize the widget again, but in the opposite direction + testWidget.resizeUp(); + QTRY_VERIFY(testWidget.repainted); QTRY_COMPARE(testWidget.paintedRegion, testWidget.mask()); } @@ -9372,17 +9377,12 @@ void tst_QWidget::translucentWidget() label.setWindowTitle(QLatin1String(QTest::currentTestFunction())); label.setFixedSize(16,16); label.setAttribute(Qt::WA_TranslucentBackground); - const QPoint labelPos = QGuiApplication::primaryScreen()->availableGeometry().topLeft(); - label.move(labelPos); + label.move(m_availableTopLeft); label.show(); QVERIFY(QTest::qWaitForWindowExposed(&label)); QPixmap widgetSnapshot = -#ifdef Q_OS_WIN - QGuiApplication::primaryScreen()->grabWindow(0, labelPos.x(), labelPos.y(), label.width(), label.height()); -#else label.grab(QRect(QPoint(0, 0), label.size())); -#endif const QImage actual = widgetSnapshot.toImage().convertToFormat(QImage::Format_RGB32); QImage expected = pm.toImage().scaled(label.devicePixelRatio() * pm.size()); expected.setDevicePixelRatio(label.devicePixelRatio()); @@ -9753,6 +9753,8 @@ void tst_QWidget::syntheticEnterLeave() }; QCursor::setPos(m_safeCursorPos); + if (!QTest::qWaitFor([this]{ return QCursor::pos() == m_safeCursorPos; })) + QSKIP("Can't move cursor"); MyWidget window; window.setWindowTitle(QLatin1String(QTest::currentTestFunction())); @@ -9793,7 +9795,8 @@ void tst_QWidget::syntheticEnterLeave() // Position the cursor in the middle of the window. const QPoint globalPos = window.mapToGlobal(QPoint(100, 100)); QCursor::setPos(globalPos); // Enter child2 and grandChild. - QTest::qWait(300); + if (!QTest::qWaitFor([globalPos]{ return QCursor::pos() == globalPos; })) + QSKIP("Can't move cursor"); QCOMPARE(window.numLeaveEvents, 0); QCOMPARE(child2->numLeaveEvents, 0); @@ -9991,68 +9994,74 @@ void tst_QWidget::taskQTBUG_4055_sendSyntheticEnterLeave() int numEnterEvents = 0, numMouseMoveEvents = 0; }; - QCursor::setPos(m_safeCursorPos); + QCursor::setPos(m_safeCursorPos); + if (!QTest::qWaitFor([this]{ return QCursor::pos() == m_safeCursorPos; })) + QSKIP("Can't move cursor"); - SELParent parent; - parent.setWindowTitle(QLatin1String(QTest::currentTestFunction())); - parent.move(200, 200); - parent.resize(200, 200); - SELChild child(&parent); - child.resize(200, 200); - parent.show(); - QVERIFY(QTest::qWaitForWindowActive(&parent)); + SELParent parent; + parent.setWindowTitle(QLatin1String(QTest::currentTestFunction())); + parent.move(200, 200); + parent.resize(200, 200); + SELChild child(&parent); + child.resize(200, 200); + parent.show(); + QVERIFY(QTest::qWaitForWindowActive(&parent)); - QCursor::setPos(child.mapToGlobal(QPoint(100, 100))); - // Make sure the cursor has entered the child. - QTRY_VERIFY(child.numEnterEvents > 0); + const QPoint childPos = child.mapToGlobal(QPoint(100, 100)); + QCursor::setPos(childPos); + if (!QTest::qWaitFor([childPos]{ return QCursor::pos() == childPos; })) + QSKIP("Can't move cursor"); - child.hide(); - child.reset(); - child.show(); + // Make sure the cursor has entered the child. + QTRY_VERIFY(child.numEnterEvents > 0); - // Make sure the child gets enter event and no mouse move event. - QTRY_COMPARE(child.numEnterEvents, 1); - QCOMPARE(child.numMouseMoveEvents, 0); + child.hide(); + child.reset(); + child.show(); - child.hide(); - child.reset(); - child.setMouseTracking(true); - child.show(); + // Make sure the child gets enter event and no mouse move event. + QTRY_COMPARE(child.numEnterEvents, 1); + QCOMPARE(child.numMouseMoveEvents, 0); - // Make sure the child gets enter event. - // Note that we verify event->button() and event->buttons() - // in SELChild::mouseMoveEvent(). - QTRY_COMPARE(child.numEnterEvents, 1); - QCOMPARE(child.numMouseMoveEvents, 0); + child.hide(); + child.reset(); + child.setMouseTracking(true); + child.show(); - // Sending synthetic enter/leave trough the parent's mousePressEvent handler. - parent.child = &child; + // Make sure the child gets enter event. + // Note that we verify event->button() and event->buttons() + // in SELChild::mouseMoveEvent(). + QTRY_COMPARE(child.numEnterEvents, 1); + QCOMPARE(child.numMouseMoveEvents, 0); - child.hide(); - child.reset(); - QTest::mouseClick(&parent, Qt::LeftButton); + // Sending synthetic enter/leave trough the parent's mousePressEvent handler. + parent.child = &child; - // Make sure the child gets enter event. - QTRY_COMPARE(child.numEnterEvents, 1); - QCOMPARE(child.numMouseMoveEvents, 0); + child.hide(); + child.reset(); + QTest::mouseClick(&parent, Qt::LeftButton); - child.hide(); - child.reset(); - QTest::keyPress(&parent, Qt::Key_Shift); - QTest::mouseClick(&parent, Qt::LeftButton); + // Make sure the child gets enter event. + QTRY_COMPARE(child.numEnterEvents, 1); + QCOMPARE(child.numMouseMoveEvents, 0); - // Make sure the child gets enter event - QTRY_COMPARE(child.numEnterEvents, 1); - QCOMPARE(child.numMouseMoveEvents, 0); - QTest::keyRelease(&child, Qt::Key_Shift); - child.hide(); - child.reset(); - child.setMouseTracking(false); - QTest::mouseClick(&parent, Qt::LeftButton); + child.hide(); + child.reset(); + QTest::keyPress(&parent, Qt::Key_Shift); + QTest::mouseClick(&parent, Qt::LeftButton); - // Make sure the child gets enter event and no mouse move event. - QTRY_COMPARE(child.numEnterEvents, 1); - QCOMPARE(child.numMouseMoveEvents, 0); + // Make sure the child gets enter event + QTRY_COMPARE(child.numEnterEvents, 1); + QCOMPARE(child.numMouseMoveEvents, 0); + QTest::keyRelease(&child, Qt::Key_Shift); + child.hide(); + child.reset(); + child.setMouseTracking(false); + QTest::mouseClick(&parent, Qt::LeftButton); + + // Make sure the child gets enter event and no mouse move event. + QTRY_COMPARE(child.numEnterEvents, 1); + QCOMPARE(child.numMouseMoveEvents, 0); } #endif @@ -10559,7 +10568,7 @@ void tst_QWidget::taskQTBUG_7532_tabOrderWithFocusProxy() void tst_QWidget::movedAndResizedAttributes() { // Use Qt::Tool as fully decorated windows have a minimum width of 160 on - QWidget w(nullptr, Qt::Tool); + QWidget w; w.setWindowTitle(QLatin1String(QTest::currentTestFunction())); w.show(); @@ -10597,11 +10606,11 @@ void tst_QWidget::movedAndResizedAttributes() QVERIFY(!w.testAttribute(Qt::WA_Resized)); w.showNormal(); - w.move(10,10); + w.move(m_availableTopLeft); QVERIFY(w.testAttribute(Qt::WA_Moved)); QVERIFY(!w.testAttribute(Qt::WA_Resized)); - w.resize(100, 100); + w.resize(m_testWidgetSize); QVERIFY(w.testAttribute(Qt::WA_Moved)); QVERIFY(w.testAttribute(Qt::WA_Resized)); }