diff options
Diffstat (limited to 'tests/auto/quick/touchmouse/tst_touchmouse.cpp')
-rw-r--r-- | tests/auto/quick/touchmouse/tst_touchmouse.cpp | 132 |
1 files changed, 132 insertions, 0 deletions
diff --git a/tests/auto/quick/touchmouse/tst_touchmouse.cpp b/tests/auto/quick/touchmouse/tst_touchmouse.cpp index b06137716c..66dde3e26c 100644 --- a/tests/auto/quick/touchmouse/tst_touchmouse.cpp +++ b/tests/auto/quick/touchmouse/tst_touchmouse.cpp @@ -150,6 +150,12 @@ public: ++touchUngrabCount; } + void dumpEventList() + { + for (const auto &event : eventList) + qDebug() << event; + } + bool event(QEvent *event) override { return QQuickItem::event(event); } @@ -185,12 +191,22 @@ class GrabMonitor : public QObject { public: QObject *exclusiveGrabber = nullptr; + int transitionCount = 0; bool fromMouseEvent = false; bool canceled = false; + void reset() + { + exclusiveGrabber = nullptr; + transitionCount = 0; + fromMouseEvent = false; + canceled = false; + } + void onGrabChanged(QObject *grabber, QPointingDevice::GrabTransition transition, const QPointerEvent *event, const QEventPoint &point) { qCDebug(lcTests) << grabber << transition << event << point << point.device(); + ++transitionCount; switch (transition) { case QPointingDevice::GrabTransition::GrabExclusive: exclusiveGrabber = grabber; @@ -247,6 +263,11 @@ private slots: void hoverEnabled(); void implicitUngrab(); + void touchCancelWillCancelMousePress(); + + void oneTouchInsideAndOneOutside(); + + void strayTouchDoesntAutograb(); protected: bool eventFilter(QObject *, QEvent *event) override @@ -1546,6 +1567,117 @@ void tst_TouchMouse::implicitUngrab() QCOMPARE(eventItem->eventList.at(0).type, QEvent::UngrabMouse); QTest::touchEvent(&window, device).release(0, p1); // clean up potential state } + +void tst_TouchMouse::touchCancelWillCancelMousePress() +{ + QQuickView window; + QVERIFY(QQuickTest::showView(window, testFileUrl("singleitem.qml"))); + QQuickItem *root = window.rootObject(); + QVERIFY(root != nullptr); + + EventItem *eventItem = root->findChild<EventItem*>("eventItem1"); + eventItem->acceptMouse = true; + eventItem->setAcceptTouchEvents(false); + QPoint p1(20, 20); + + // Begin a new touch, that gets converted to a mouse press + QTest::touchEvent(&window, device).press(0, p1); + QCOMPARE(eventItem->eventList.count(), 1); + QCOMPARE(eventItem->eventList.at(0).type, QEvent::MouseButtonPress); + + // Cancel it... + QTouchEvent cancelEvent(QEvent::TouchCancel, device); + QCoreApplication::sendEvent(&window, &cancelEvent); + QCOMPARE(eventItem->eventList.count(), 3); + QCOMPARE(eventItem->eventList.at(1).type, QEvent::TouchCancel); + QCOMPARE(eventItem->eventList.at(2).type, QEvent::UngrabMouse); + + // Begin a second touch. Since the last one was cancelled, this + // should end up as a new mouse press on the target item. + QTest::touchEvent(&window, device).press(0, p1); + QVERIFY(eventItem->eventList.count() >= 5); + QCOMPARE(eventItem->eventList.at(3).type, QEvent::MouseButtonPress); + + QTest::touchEvent(&window, device).release(0, p1); // clean up potential state +} + +void tst_TouchMouse::oneTouchInsideAndOneOutside() // QTBUG-102996 +{ + QQuickView window; + QVERIFY(QQuickTest::showView(window, testFileUrl("oneMouseArea.qml"))); + QQuickItem *root = window.rootObject(); + QVERIFY(root); + QQuickMouseArea *ma = root->findChild<QQuickMouseArea*>(); + QVERIFY(ma); + + // Press the MouseArea + QPoint p1 = ma->mapToScene(ma->boundingRect().center()).toPoint(); + QTest::touchEvent(&window, device).press(1, p1); + QQuickTouchUtils::flush(&window); + QVERIFY(ma->pressed()); + + // Tap outside the MouseArea with a second finger + QPoint p2(100, 100); + QTest::touchEvent(&window, device).stationary(1).press(2, p2); + QQuickTouchUtils::flush(&window); + QTest::touchEvent(&window, device).stationary(1).release(2, p2); + QQuickTouchUtils::flush(&window); + QVERIFY(ma->pressed()); + + // Press again outside the MouseArea with a second finger + QTest::touchEvent(&window, device).stationary(1).press(2, p2); + + // Release the first finger: MouseArea should be released + QTest::touchEvent(&window, device).release(1, p1).stationary(2); + QQuickTouchUtils::flush(&window); + QCOMPARE(ma->pressed(), false); + + // Release the second finger + QTest::touchEvent(&window, device).release(2, p2); + QQuickTouchUtils::flush(&window); +} + +void tst_TouchMouse::strayTouchDoesntAutograb() // QTBUG-107867 +{ + QQuickView window; + QVERIFY(QQuickTest::showView(window, testFileUrl("singleitem.qml"))); + QQuickItem *root = window.rootObject(); + QVERIFY(root); + EventItem *eventItem = root->findChild<EventItem*>(); + QVERIFY(eventItem); + // This item accepts (synth-)mouse events but NOT touch + eventItem->acceptMouse = true; + QCOMPARE(eventItem->acceptTouchEvents(), false); // the default in Qt 6 + QPoint p1(6, 6); + grabMonitor.reset(); + + // Begin a new touch, that gets converted to a mouse press + QTest::touchEvent(&window, device).press(0, p1); + QQuickTouchUtils::flush(&window); + qCDebug(lcTests) << "after touch press:" << eventItem->eventList; + QCOMPARE(eventItem->eventList.size(), 1); + QCOMPARE(eventItem->eventList.at(0).type, QEvent::MouseButtonPress); + QCOMPARE(grabMonitor.exclusiveGrabber, eventItem); + + // Drag + for (int i = 0; i < 3; ++i) { + QTest::touchEvent(&window, device).move(0, p1 + QPoint(i * 5, i * 5), &window); + QQuickTouchUtils::flush(&window); + QCOMPARE(grabMonitor.transitionCount, 1); // no new grab + QCOMPARE(eventItem->eventList.size(), i + 2); + QCOMPARE(eventItem->eventList.last().type, QEvent::MouseMove); + } + + // Press an extra point: EventItem should see nothing + QTest::touchEvent(&window, device).stationary(0).press(1, p1); + QQuickTouchUtils::flush(&window); + qCDebug(lcTests) << "after press of second touchpoint:" << eventItem->eventList; + QCOMPARE(eventItem->eventList.size(), 4); + QCOMPARE(grabMonitor.transitionCount, 1); // no new grab + + QTest::touchEvent(&window, device).release(0, p1).release(1, p1); +} + QTEST_MAIN(tst_TouchMouse) #include "tst_touchmouse.moc" |