aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/quick/qquickwindow
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@qt.io>2018-02-12 13:26:55 +0100
committerLiang Qi <liang.qi@qt.io>2018-02-12 16:31:13 +0100
commit4d525de33e2ee55e69bb6c90fc11049a0f8b36b5 (patch)
treec9808baeabb1121f488a7b59ffff314cc62d80e8 /tests/auto/quick/qquickwindow
parent47cd9da96371ccd495f6caabe1c6853258210ebb (diff)
parent3e3c6717ba634825a65069541500c40645a808ee (diff)
Merge remote-tracking branch 'origin/5.10' into 5.11
Conflicts: src/imports/shapes/qquickshape.cpp src/imports/shapes/qquickshape_p_p.h src/qml/compiler/qqmlpropertycachecreator_p.h src/qml/jsruntime/qv4value_p.h src/quick/items/qquickloader_p.h tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp tools/qmlprofiler/qmlprofilerapplication.cpp Change-Id: Iafc66ae84bf78630ed72a986acb678e9d19e3a69
Diffstat (limited to 'tests/auto/quick/qquickwindow')
-rw-r--r--tests/auto/quick/qquickwindow/tst_qquickwindow.cpp114
1 files changed, 108 insertions, 6 deletions
diff --git a/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp b/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp
index 666f80fce1..fe9e8bb1fa 100644
--- a/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp
+++ b/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp
@@ -292,6 +292,70 @@ protected:
}
};
+class MouseRecordingWindow : public QQuickWindow
+{
+public:
+ explicit MouseRecordingWindow(QWindow *parent = nullptr) : QQuickWindow(parent) { }
+
+protected:
+ void mousePressEvent(QMouseEvent *event) override {
+ qCDebug(lcTests) << event;
+ m_mouseEvents << *event;
+ QQuickWindow::mousePressEvent(event);
+ }
+ void mouseMoveEvent(QMouseEvent *event) override {
+ qCDebug(lcTests) << event;
+ m_mouseEvents << *event;
+ QQuickWindow::mouseMoveEvent(event);
+ }
+ void mouseReleaseEvent(QMouseEvent *event) override {
+ qCDebug(lcTests) << event;
+ m_mouseEvents << *event;
+ QQuickWindow::mouseReleaseEvent(event);
+ }
+
+public:
+ QList<QMouseEvent> m_mouseEvents;
+};
+
+class MouseRecordingItem : public QQuickItem
+{
+public:
+ MouseRecordingItem(bool acceptTouch, QQuickItem *parent = nullptr)
+ : QQuickItem(parent)
+ , m_acceptTouch(acceptTouch)
+ {
+ setSize(QSizeF(300, 300));
+ setAcceptedMouseButtons(Qt::LeftButton);
+ }
+
+protected:
+ void touchEvent(QTouchEvent* event) override {
+ event->setAccepted(m_acceptTouch);
+ m_touchEvents << *event;
+ qCDebug(lcTests) << "accepted?" << event->isAccepted() << event;
+ }
+ void mousePressEvent(QMouseEvent *event) override {
+ qCDebug(lcTests) << event;
+ m_mouseEvents << *event;
+ }
+ void mouseMoveEvent(QMouseEvent *event) override {
+ qCDebug(lcTests) << event;
+ m_mouseEvents << *event;
+ }
+ void mouseReleaseEvent(QMouseEvent *event) override {
+ qCDebug(lcTests) << event;
+ m_mouseEvents << *event;
+ }
+
+public:
+ QList<QMouseEvent> m_mouseEvents;
+ QList<QTouchEvent> m_touchEvents;
+
+private:
+ bool m_acceptTouch;
+};
+
class tst_qquickwindow : public QQmlDataTest
{
Q_OBJECT
@@ -330,6 +394,8 @@ private slots:
void mergeTouchPointLists();
void mouseFromTouch_basic();
+ void synthMouseFromTouch_data();
+ void synthMouseFromTouch();
void clearWindow();
@@ -705,9 +771,8 @@ void tst_qquickwindow::touchEvent_propagation()
// single touch to top item, should be received by middle item
QTest::touchEvent(window, touchDevice).press(0, pointInTopItem, window);
- QTest::qWait(50);
+ QTRY_COMPARE(middleItem->lastEvent.touchPoints.count(), 1);
QVERIFY(topItem->lastEvent.touchPoints.isEmpty());
- QCOMPARE(middleItem->lastEvent.touchPoints.count(), 1);
QVERIFY(bottomItem->lastEvent.touchPoints.isEmpty());
COMPARE_TOUCH_DATA(middleItem->lastEvent, makeTouchData(QEvent::TouchBegin, window, Qt::TouchPointPressed,
makeTouchPoint(middleItem, middleItem->mapFromItem(topItem, pos))));
@@ -716,9 +781,8 @@ void tst_qquickwindow::touchEvent_propagation()
// touch top and middle items, middle item should get both events
QTest::touchEvent(window, touchDevice).press(0, pointInTopItem, window)
.press(1, pointInMiddleItem, window);
- QTest::qWait(50);
+ QTRY_COMPARE(middleItem->lastEvent.touchPoints.count(), 2);
QVERIFY(topItem->lastEvent.touchPoints.isEmpty());
- QCOMPARE(middleItem->lastEvent.touchPoints.count(), 2);
QVERIFY(bottomItem->lastEvent.touchPoints.isEmpty());
COMPARE_TOUCH_DATA(middleItem->lastEvent, makeTouchData(QEvent::TouchBegin, window, Qt::TouchPointPressed,
(QList<QTouchEvent::TouchPoint>() << makeTouchPoint(middleItem, middleItem->mapFromItem(topItem, pos))
@@ -736,10 +800,9 @@ void tst_qquickwindow::touchEvent_propagation()
// touch top and middle items, bottom item should get all events
QTest::touchEvent(window, touchDevice).press(0, pointInTopItem, window)
.press(1, pointInMiddleItem, window);
- QTest::qWait(50);
+ QTRY_COMPARE(bottomItem->lastEvent.touchPoints.count(), 2);
QVERIFY(topItem->lastEvent.touchPoints.isEmpty());
QVERIFY(middleItem->lastEvent.touchPoints.isEmpty());
- QCOMPARE(bottomItem->lastEvent.touchPoints.count(), 2);
COMPARE_TOUCH_DATA(bottomItem->lastEvent, makeTouchData(QEvent::TouchBegin, window, Qt::TouchPointPressed,
(QList<QTouchEvent::TouchPoint>() << makeTouchPoint(bottomItem, bottomItem->mapFromItem(topItem, pos))
<< makeTouchPoint(bottomItem, bottomItem->mapFromItem(middleItem, pos)) )));
@@ -1132,6 +1195,45 @@ void tst_qquickwindow::mouseFromTouch_basic()
delete item;
}
+void tst_qquickwindow::synthMouseFromTouch_data()
+{
+ QTest::addColumn<bool>("synthMouse"); // AA_SynthesizeMouseForUnhandledTouchEvents
+ QTest::addColumn<bool>("acceptTouch"); // QQuickItem::touchEvent: setAccepted()
+
+ QTest::newRow("no synth, accept") << false << true; // suitable for touch-capable UIs
+ QTest::newRow("no synth, don't accept") << false << false;
+ QTest::newRow("synth and accept") << true << true;
+ QTest::newRow("synth, don't accept") << true << false; // the default
+}
+
+void tst_qquickwindow::synthMouseFromTouch()
+{
+ QFETCH(bool, synthMouse);
+ QFETCH(bool, acceptTouch);
+
+ QCoreApplication::setAttribute(Qt::AA_SynthesizeMouseForUnhandledTouchEvents, synthMouse);
+ QScopedPointer<MouseRecordingWindow> window(new MouseRecordingWindow);
+ QScopedPointer<MouseRecordingItem> item(new MouseRecordingItem(acceptTouch, nullptr));
+ item->setParentItem(window->contentItem());
+ window->resize(250, 250);
+ window->setPosition(100, 100);
+ window->setTitle(QTest::currentTestFunction());
+ window->show();
+ QVERIFY(QTest::qWaitForWindowActive(window.data()));
+
+ QPoint p1 = QPoint(20, 20);
+ QPoint p2 = QPoint(30, 30);
+ QTest::touchEvent(window.data(), touchDevice).press(0, p1, window.data());
+ QTest::touchEvent(window.data(), touchDevice).move(0, p2, window.data());
+ QTest::touchEvent(window.data(), touchDevice).release(0, p2, window.data());
+
+ QCOMPARE(item->m_touchEvents.count(), 3);
+ QCOMPARE(item->m_mouseEvents.count(), acceptTouch ? 0 : 3);
+ QCOMPARE(window->m_mouseEvents.count(), 0);
+ for (const QMouseEvent &ev : item->m_mouseEvents)
+ QCOMPARE(ev.source(), Qt::MouseEventSynthesizedByQt);
+}
+
void tst_qquickwindow::clearWindow()
{
QQuickWindow *window = new QQuickWindow;