From 2d1de5a5dfb3fa88a61ead2db7988526438faee8 Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Thu, 9 Feb 2023 17:29:45 +0100 Subject: [PATCH] tst_QQuickMultiPointTouchArea::inFlickable: make synth-mouse realistic Since 1d445eb5b1a14da342382a088f4e1cc5492ea32e this test has been sending mouse events interleaved with touch events, and I believe the intention was to simulate systems or touch drivers that send synth-mouse events whether the application wants them or not. Let's at least make them look synthetic to Qt Quick. It's getting harder to think of workarounds for Flickable not to react to real-looking mouse events as if they were actually real. Change-Id: I7bbb6ef2d8e93cd9a6a4875a60b4ea02e254de9c Reviewed-by: Shawn Rutledge --- .../tst_qquickmultipointtoucharea.cpp | 32 +++++++++++++++---- 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/tests/auto/quick/qquickmultipointtoucharea/tst_qquickmultipointtoucharea.cpp b/tests/auto/quick/qquickmultipointtoucharea/tst_qquickmultipointtoucharea.cpp index 30fc37b216..532a910320 100644 --- a/tests/auto/quick/qquickmultipointtoucharea/tst_qquickmultipointtoucharea.cpp +++ b/tests/auto/quick/qquickmultipointtoucharea/tst_qquickmultipointtoucharea.cpp @@ -607,7 +607,10 @@ void tst_QQuickMultiPointTouchArea::inFlickable() // The stray mouse events simulate OS-level synth-from-touch, and should not interfere. p1 = QPoint(20,100); QTest::touchEvent(window.data(), device).press(0, p1).press(1, p2); - QTest::mousePress(window.data(), Qt::LeftButton, Qt::NoModifier, p1); + QWindowSystemInterface::handleMouseEvent(window.data(), device, p1, window->mapToGlobal(p1), + Qt::LeftButton, Qt::LeftButton, QEvent::MouseButtonPress, + Qt::NoModifier, Qt::MouseEventSynthesizedBySystem); + qApp->processEvents(); QQuickTouchUtils::flush(window.data()); QCOMPARE(point11->pressed(), true); @@ -620,7 +623,10 @@ void tst_QQuickMultiPointTouchArea::inFlickable() QTest::qWait(250); p1 += delta; p2 += delta; QTest::touchEvent(window.data(), device).move(0, p1).move(1, p2); - QTest::mouseMove(window.data(), p1); + QWindowSystemInterface::handleMouseEvent(window.data(), device, p1, window->mapToGlobal(p1), + Qt::LeftButton, Qt::NoButton, QEvent::MouseMove, + Qt::NoModifier, Qt::MouseEventSynthesizedBySystem); + qApp->processEvents(); QQuickTouchUtils::flush(window.data()); qCDebug(lcTests, "after drags %d to %d,%d and %d,%d contentY is %lf", i, p1.x(), p1.y(), p2.x(), p2.y(), flickable->contentY()); @@ -633,7 +639,10 @@ void tst_QQuickMultiPointTouchArea::inFlickable() QCOMPARE(window->rootObject()->property("touchCount").toInt(), 2); QTest::touchEvent(window.data(), device).release(0, p1).release(1, p2); - QTest::mouseRelease(window.data(), Qt::LeftButton, Qt::NoModifier, p1); + QWindowSystemInterface::handleMouseEvent(window.data(), device, p1, window->mapToGlobal(p1), + Qt::NoButton, Qt::LeftButton, QEvent::MouseButtonRelease, + Qt::NoModifier, Qt::MouseEventSynthesizedBySystem); + qApp->processEvents(); QQuickTouchUtils::flush(window.data()); QTRY_VERIFY(!flickable->isMoving()); @@ -643,10 +652,15 @@ void tst_QQuickMultiPointTouchArea::inFlickable() p2 = QPoint(40,100); QTest::touchEvent(window.data(), device).press(0, p1).press(1, p2); QQuickTouchUtils::flush(window.data()); + QCOMPARE(point11->pressed(), true); + QCOMPARE(point12->pressed(), true); // ensure that mouse events do not fall through to the Flickable mpta->setMaximumTouchPoints(3); mpta->setAcceptedMouseButtons(Qt::LeftButton); - QTest::mousePress(window.data(), Qt::LeftButton, Qt::NoModifier, p1); + QWindowSystemInterface::handleMouseEvent(window.data(), device, p1, window->mapToGlobal(p1), + Qt::LeftButton, Qt::LeftButton, QEvent::MouseButtonPress, + Qt::NoModifier, Qt::MouseEventSynthesizedBySystem); + qApp->processEvents(); QCOMPARE(point11->pressed(), true); QCOMPARE(point12->pressed(), true); @@ -659,7 +673,10 @@ void tst_QQuickMultiPointTouchArea::inFlickable() delta = QPoint(0, 15); p1 += delta; p2 += delta; QTest::touchEvent(window.data(), device).move(0, p1).move(1, p2); - QTest::mouseMove(window.data(), p1); + QWindowSystemInterface::handleMouseEvent(window.data(), device, p1, window->mapToGlobal(p1), + Qt::LeftButton, Qt::NoButton, QEvent::MouseMove, + Qt::NoModifier, Qt::MouseEventSynthesizedBySystem); + qApp->processEvents(); QQuickTouchUtils::flush(window.data()); qCDebug(lcTests, "after drags %d to %d,%d and %d,%d contentY is %lf", i, p1.x(), p1.y(), p2.x(), p2.y(), flickable->contentY()); @@ -670,7 +687,10 @@ void tst_QQuickMultiPointTouchArea::inFlickable() QCOMPARE(point12->pressed(), true); QTest::touchEvent(window.data(), device).release(0, p1).release(1, p2); - QTest::mouseRelease(window.data(), Qt::LeftButton, Qt::NoModifier, p1); + QWindowSystemInterface::handleMouseEvent(window.data(), device, p1, window->mapToGlobal(p1), + Qt::NoButton, Qt::LeftButton, QEvent::MouseButtonRelease, + Qt::NoModifier, Qt::MouseEventSynthesizedBySystem); + qApp->processEvents(); QQuickTouchUtils::flush(window.data()); }