tst_QQuickMultiPointTouchArea::inFlickable: make synth-mouse realistic

Since 1d445eb5b1 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 <shawn.rutledge@qt.io>
This commit is contained in:
Shawn Rutledge 2023-02-09 17:29:45 +01:00
parent 5171bcd9ce
commit 2d1de5a5df
1 changed files with 26 additions and 6 deletions

View File

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