tests: fix and un-blacklist tst_qgraphicsview::hoverLeave

Tests should not use QCursor to emulate mouse move, see QCursor::setPos() docs.

The flakiness of the test on XCB is not surprising when the test queries geometry
even before the window has been shown. With the re-factored version I could not
reproduce flakiness anymore.

Removed Q_OS_MAC and closed QTBUG-26274 as test passes on macOS from which I
assume that the underlying issue has been fixed.

Removed Q_OS_QNX ifdef as test does not rely on QCursor anymore.

This patch also fixes the issues on minimal / offscreen platform plugins.
QCursor::setPos() is evil for auto test purposes.

Note:

We intentionally use QTest::mouseMove(QWindow *window, ..), not the QWidget overload.
The QWindow version gets routed through QWSI, which ensures that all necessary events
are generated as expect. In QWidget code path this is currently disabled by
QTEST_QPA_MOUSE_HANDLING.

Change-Id: I285c26cff09e3f2750f8c2abbb1f46c8f7be984a
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
(cherry picked from commit 1af927976ac953f922e35d71a16a32d328bb2efd)
Reviewed-by: Tony Sarajärvi <tony.sarajarvi@qt.io>
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Reviewed-by: Liang Qi <liang.qi@qt.io>
This commit is contained in:
Gatis Paeglis 2017-09-07 14:40:58 +02:00
parent db333d6dba
commit 0aba5546ef
2 changed files with 19 additions and 31 deletions

View File

@ -12,7 +12,5 @@ xcb
xcb
[forwardMousePress]
xcb
[hoverLeave]
xcb
[resizeAnchor]
xcb

View File

@ -4777,8 +4777,6 @@ class GraphicsItemWithHover : public QGraphicsRectItem
{
public:
GraphicsItemWithHover()
: receivedEnterEvent(false), receivedLeaveEvent(false),
enterWidget(0), leaveWidget(0)
{
setRect(0, 0, 100, 100);
setAcceptHoverEvents(true);
@ -4786,6 +4784,9 @@ public:
bool sceneEvent(QEvent *event)
{
if (!checkEvents) // ensures that we don't look at stray events before we are ready
return QGraphicsRectItem::sceneEvent(event);
if (event->type() == QEvent::GraphicsSceneHoverEnter) {
receivedEnterEvent = true;
enterWidget = static_cast<QGraphicsSceneHoverEvent *>(event)->widget();
@ -4796,50 +4797,39 @@ public:
return QGraphicsRectItem::sceneEvent(event);
}
bool receivedEnterEvent;
bool receivedLeaveEvent;
QWidget *enterWidget;
QWidget *leaveWidget;
bool receivedEnterEvent = false;
bool receivedLeaveEvent = false;
QWidget *enterWidget = nullptr;
QWidget *leaveWidget = nullptr;
bool checkEvents = false;
};
void tst_QGraphicsView::hoverLeave()
{
if (platformName == QStringLiteral("cocoa")) {
QSKIP("Insignificant on OSX");
} else if (platformName == QStringLiteral("minimal")
|| (platformName == QStringLiteral("offscreen"))) {
QSKIP("Fails in minimal/offscreen platforms if forwardMouseDoubleClick has been run");
}
const QRect availableGeometry = QGuiApplication::primaryScreen()->availableGeometry();
QGraphicsScene scene;
QGraphicsView view(&scene);
view.resize(160, 160);
view.move(availableGeometry.center() - QPoint(80, 80));
GraphicsItemWithHover *item = new GraphicsItemWithHover;
scene.addItem(item);
// move the cursor out of the way
const QPoint outOfWindow = view.geometry().topRight() + QPoint(50, 0);
QCursor::setPos(outOfWindow);
view.showNormal();
qApp->setActiveWindow(&view);
QVERIFY(QTest::qWaitForWindowActive(&view));
QVERIFY(QTest::qWaitForWindowExposed(&view));
QPoint pos = view.viewport()->mapToGlobal(view.mapFromScene(item->mapToScene(10, 10)));
QCursor::setPos(pos);
#if defined(Q_OS_QNX)
QEXPECT_FAIL("", "QCursor does not set native cursor on QNX", Abort);
#endif
QWindow *viewWindow = view.window()->windowHandle();
QPoint posOutsideItem = view.mapFromScene(item->mapToScene(0, 0)) - QPoint(5, 0);
QPoint posOutsideItemGlobal = view.mapToGlobal(posOutsideItem);
QPoint posOutsideItemInWindow = viewWindow->mapFromGlobal(posOutsideItemGlobal);
QTest::mouseMove(viewWindow, posOutsideItemInWindow);
item->checkEvents = true;
QPoint posInItemGlobal = view.mapToGlobal(view.mapFromScene(item->mapToScene(10, 10)));
QTest::mouseMove(viewWindow, viewWindow->mapFromGlobal(posInItemGlobal));
QTRY_VERIFY(item->receivedEnterEvent);
QCOMPARE(item->enterWidget, view.viewport());
QCursor::setPos(outOfWindow);
#ifdef Q_OS_MAC
QEXPECT_FAIL("", "QTBUG-26274 - behaviour regression", Abort);
#endif
QTest::mouseMove(viewWindow, posOutsideItemInWindow);
QTRY_VERIFY(item->receivedLeaveEvent);
QCOMPARE(item->leaveWidget, view.viewport());
}