diff options
author | Liang Qi <liang.qi@qt.io> | 2017-03-14 10:49:51 +0100 |
---|---|---|
committer | Liang Qi <liang.qi@qt.io> | 2017-03-14 10:49:51 +0100 |
commit | 12e82111ab86669969430ab10118236d8d846d33 (patch) | |
tree | fb2345160fbe9d46cb61212f4a5eac81389464ba /tests/auto | |
parent | 30635ee2424dbd08bb5c2170be0c2dc5f9d23b2c (diff) | |
parent | 77e0dc0485953427320ed0b442ba24eef4f9d73b (diff) |
Merge remote-tracking branch 'origin/5.9' into dev
Change-Id: I0ec164ce6e8099e6e4d6b40a3c7340737473ef4b
Diffstat (limited to 'tests/auto')
6 files changed, 402 insertions, 9 deletions
diff --git a/tests/auto/qml/debugger/qv4debugger/tst_qv4debugger.cpp b/tests/auto/qml/debugger/qv4debugger/tst_qv4debugger.cpp index 6793596174..56320b8365 100644 --- a/tests/auto/qml/debugger/qv4debugger/tst_qv4debugger.cpp +++ b/tests/auto/qml/debugger/qv4debugger/tst_qv4debugger.cpp @@ -176,6 +176,7 @@ public: , m_captureContextInfo(false) , m_thrownValue(-1) , collector(engine) + , m_resumeSpeed(QV4Debugger::FullThrottle) , m_debugger(0) { } @@ -214,7 +215,7 @@ public slots: if (m_captureContextInfo) captureContextInfo(debugger); - debugger->resume(QV4Debugger::FullThrottle); + debugger->resume(m_resumeSpeed); } public: @@ -280,6 +281,7 @@ public: int context; }; QVector<ExpressionRequest> m_expressionRequests; + QV4Debugger::Speed m_resumeSpeed; QList<QJsonObject> m_expressionResults; QList<QJsonArray> m_expressionRefs; QV4Debugger *m_debugger; @@ -324,7 +326,10 @@ private slots: void breakInWith(); void evaluateExpression(); + void stepToEndOfScript(); + void lastLineOfLoop_data(); + void lastLineOfLoop(); private: QV4Debugger *debugger() const { @@ -758,6 +763,70 @@ void tst_qv4debugger::evaluateExpression() } } +void tst_qv4debugger::stepToEndOfScript() +{ + QString script = + "var ret = 0;\n" + "ret += 4;\n" + "ret += 1;\n" + "ret += 5;\n"; + + debugger()->addBreakPoint("toEnd", 1); + m_debuggerAgent->m_resumeSpeed = QV4Debugger::StepOver; + evaluateJavaScript(script, "toEnd"); + QVERIFY(m_debuggerAgent->m_wasPaused); + QCOMPARE(m_debuggerAgent->m_pauseReason, QV4Debugger::Step); + QCOMPARE(m_debuggerAgent->m_statesWhenPaused.count(), 5); + for (int i = 0; i < 4; ++i) { + QV4Debugger::ExecutionState state = m_debuggerAgent->m_statesWhenPaused.at(i); + QCOMPARE(state.fileName, QString("toEnd")); + QCOMPARE(state.lineNumber, i + 1); + } + + QV4Debugger::ExecutionState state = m_debuggerAgent->m_statesWhenPaused.at(4); + QCOMPARE(state.fileName, QString("toEnd")); + QCOMPARE(state.lineNumber, -4); // A return instruction without proper line number. +} + +void tst_qv4debugger::lastLineOfLoop_data() +{ + QTest::addColumn<QString>("loopHead"); + QTest::addColumn<QString>("loopTail"); + + QTest::newRow("for") << "for (var i = 0; i < 10; ++i) {\n" << "}\n"; + QTest::newRow("for..in") << "for (var i in [0, 1, 2, 3, 4]) {\n" << "}\n"; + QTest::newRow("while") << "while (ret < 10) {\n" << "}\n"; + QTest::newRow("do..while") << "do {\n" << "} while (ret < 10);\n"; +} + +void tst_qv4debugger::lastLineOfLoop() +{ + QFETCH(QString, loopHead); + QFETCH(QString, loopTail); + + QString script = + "var ret = 0;\n" + + loopHead + + " if (ret == 2)\n" + " ret += 4;\n" // breakpoint, then step over + " else \n" + " ret += 1;\n" + + loopTail; + + debugger()->addBreakPoint("trueBranch", 4); + m_debuggerAgent->m_resumeSpeed = QV4Debugger::StepOver; + evaluateJavaScript(script, "trueBranch"); + QVERIFY(m_debuggerAgent->m_wasPaused); + QCOMPARE(m_debuggerAgent->m_pauseReason, QV4Debugger::Step); + QVERIFY(m_debuggerAgent->m_statesWhenPaused.count() > 1); + QV4Debugger::ExecutionState firstState = m_debuggerAgent->m_statesWhenPaused.first(); + QCOMPARE(firstState.fileName, QString("trueBranch")); + QCOMPARE(firstState.lineNumber, 4); + QV4Debugger::ExecutionState secondState = m_debuggerAgent->m_statesWhenPaused.at(1); + QCOMPARE(secondState.fileName, QString("trueBranch")); + QCOMPARE(secondState.lineNumber, 7); +} + QTEST_MAIN(tst_qv4debugger) #include "tst_qv4debugger.moc" diff --git a/tests/auto/quick/qquickmultipointtoucharea/BLACKLIST b/tests/auto/quick/qquickmultipointtoucharea/BLACKLIST deleted file mode 100644 index 1777af9e0c..0000000000 --- a/tests/auto/quick/qquickmultipointtoucharea/BLACKLIST +++ /dev/null @@ -1,2 +0,0 @@ -[inFlickable] -* diff --git a/tests/auto/quick/qquickmultipointtoucharea/tst_qquickmultipointtoucharea.cpp b/tests/auto/quick/qquickmultipointtoucharea/tst_qquickmultipointtoucharea.cpp index 2872556a94..87acd67f6a 100644 --- a/tests/auto/quick/qquickmultipointtoucharea/tst_qquickmultipointtoucharea.cpp +++ b/tests/auto/quick/qquickmultipointtoucharea/tst_qquickmultipointtoucharea.cpp @@ -800,7 +800,7 @@ void tst_QQuickMultiPointTouchArea::inFlickable2() QVERIFY(flickable->contentY() < 0); QVERIFY(flickable->isMoving()); - QCOMPARE(point11->pressed(), true); + QCOMPARE(point11->pressed(), false); QTest::touchEvent(window.data(), device).release(0, p1); QQuickTouchUtils::flush(window.data()); diff --git a/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp b/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp index cd503a88d4..d454f9b7bc 100644 --- a/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp +++ b/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp @@ -28,6 +28,7 @@ #include <qtest.h> #include <QDebug> +#include <QMimeData> #include <QTouchEvent> #include <QtQuick/QQuickItem> #include <QtQuick/QQuickView> @@ -372,6 +373,8 @@ private slots: void grabContentItemToImage(); + void testDragEventPropertyPropagation(); + private: QTouchDevice *touchDevice; QTouchDevice *touchDeviceWithVelocity; @@ -2567,6 +2570,261 @@ void tst_qquickwindow::grabContentItemToImage() QTRY_COMPARE(created->property("success").toInt(), 1); } +class TestDropTarget : public QQuickItem +{ + Q_OBJECT +public: + TestDropTarget(QQuickItem *parent = 0) + : QQuickItem(parent) + , enterDropAction(Qt::CopyAction) + , moveDropAction(Qt::CopyAction) + , dropDropAction(Qt::CopyAction) + , enterAccept(true) + , moveAccept(true) + , dropAccept(true) + { + setFlags(ItemAcceptsDrops); + } + + void reset() + { + enterDropAction = Qt::CopyAction; + moveDropAction = Qt::CopyAction; + dropDropAction = Qt::CopyAction; + enterAccept = true; + moveAccept = true; + dropAccept = true; + } + + void dragEnterEvent(QDragEnterEvent *event) + { + event->setAccepted(enterAccept); + event->setDropAction(enterDropAction); + } + + void dragMoveEvent(QDragMoveEvent *event) + { + event->setAccepted(moveAccept); + event->setDropAction(moveDropAction); + } + + void dropEvent(QDropEvent *event) + { + event->setAccepted(dropAccept); + event->setDropAction(dropDropAction); + } + + Qt::DropAction enterDropAction; + Qt::DropAction moveDropAction; + Qt::DropAction dropDropAction; + bool enterAccept; + bool moveAccept; + bool dropAccept; +}; + +class DragEventTester { +public: + DragEventTester() + : pos(60, 60) + , actions(Qt::CopyAction | Qt::MoveAction | Qt::LinkAction) + , buttons(Qt::LeftButton) + , modifiers(Qt::NoModifier) + { + } + + ~DragEventTester() { + qDeleteAll(events); + events.clear(); + enterEvent = 0; + moveEvent = 0; + dropEvent = 0; + leaveEvent = 0; + } + + void addEnterEvent() + { + enterEvent = new QDragEnterEvent(pos, actions, &data, buttons, modifiers); + events.append(enterEvent); + } + + void addMoveEvent() + { + moveEvent = new QDragMoveEvent(pos, actions, &data, buttons, modifiers, QEvent::DragMove); + events.append(moveEvent); + } + + void addDropEvent() + { + dropEvent = new QDropEvent(pos, actions, &data, buttons, modifiers, QEvent::Drop); + events.append(dropEvent); + } + + void addLeaveEvent() + { + leaveEvent = new QDragLeaveEvent(); + events.append(leaveEvent); + } + + void sendDragEventSequence(QQuickWindow *window) const { + for (int i = 0; i < events.size(); ++i) { + QCoreApplication::sendEvent(window, events[i]); + } + } + + // Used for building events. + QMimeData data; + QPoint pos; + Qt::DropActions actions; + Qt::MouseButtons buttons; + Qt::KeyboardModifiers modifiers; + + // Owns events. + QList<QEvent *> events; + + // Non-owner pointers for easy acccess. + QDragEnterEvent *enterEvent; + QDragMoveEvent *moveEvent; + QDropEvent *dropEvent; + QDragLeaveEvent *leaveEvent; +}; + +void tst_qquickwindow::testDragEventPropertyPropagation() +{ + QQuickWindow window; + TestDropTarget dropTarget(window.contentItem()); + + // Setting the size is important because the QQuickWindow checks if the drag happened inside + // the drop target. + dropTarget.setSize(QSizeF(100, 100)); + + // Test enter events property propagation. + // For enter events, only isAccepted gets propagated. + { + DragEventTester builder; + dropTarget.enterAccept = false; + dropTarget.enterDropAction = Qt::IgnoreAction; + builder.addEnterEvent(); builder.addMoveEvent(); builder.addLeaveEvent(); + builder.sendDragEventSequence(&window); + QDragEnterEvent* enterEvent = builder.enterEvent; + QCOMPARE(enterEvent->isAccepted(), dropTarget.enterAccept); + } + { + DragEventTester builder; + dropTarget.enterAccept = false; + dropTarget.enterDropAction = Qt::CopyAction; + builder.addEnterEvent(); builder.addMoveEvent(); builder.addLeaveEvent(); + builder.sendDragEventSequence(&window); + QDragEnterEvent* enterEvent = builder.enterEvent; + QCOMPARE(enterEvent->isAccepted(), dropTarget.enterAccept); + } + { + DragEventTester builder; + dropTarget.enterAccept = true; + dropTarget.enterDropAction = Qt::IgnoreAction; + builder.addEnterEvent(); builder.addMoveEvent(); builder.addLeaveEvent(); + builder.sendDragEventSequence(&window); + QDragEnterEvent* enterEvent = builder.enterEvent; + QCOMPARE(enterEvent->isAccepted(), dropTarget.enterAccept); + } + { + DragEventTester builder; + dropTarget.enterAccept = true; + dropTarget.enterDropAction = Qt::CopyAction; + builder.addEnterEvent(); builder.addMoveEvent(); builder.addLeaveEvent(); + builder.sendDragEventSequence(&window); + QDragEnterEvent* enterEvent = builder.enterEvent; + QCOMPARE(enterEvent->isAccepted(), dropTarget.enterAccept); + } + + // Test move events property propagation. + // For move events, both isAccepted and dropAction get propagated. + dropTarget.reset(); + { + DragEventTester builder; + dropTarget.moveAccept = false; + dropTarget.moveDropAction = Qt::IgnoreAction; + builder.addEnterEvent(); builder.addMoveEvent(); builder.addLeaveEvent(); + builder.sendDragEventSequence(&window); + QDragMoveEvent* moveEvent = builder.moveEvent; + QCOMPARE(moveEvent->isAccepted(), dropTarget.moveAccept); + QCOMPARE(moveEvent->dropAction(), dropTarget.moveDropAction); + } + { + DragEventTester builder; + dropTarget.moveAccept = false; + dropTarget.moveDropAction = Qt::CopyAction; + builder.addEnterEvent(); builder.addMoveEvent(); builder.addLeaveEvent(); + builder.sendDragEventSequence(&window); + QDragMoveEvent* moveEvent = builder.moveEvent; + QCOMPARE(moveEvent->isAccepted(), dropTarget.moveAccept); + QCOMPARE(moveEvent->dropAction(), dropTarget.moveDropAction); + } + { + DragEventTester builder; + dropTarget.moveAccept = true; + dropTarget.moveDropAction = Qt::IgnoreAction; + builder.addEnterEvent(); builder.addMoveEvent(); builder.addLeaveEvent(); + builder.sendDragEventSequence(&window); + QDragMoveEvent* moveEvent = builder.moveEvent; + QCOMPARE(moveEvent->isAccepted(), dropTarget.moveAccept); + QCOMPARE(moveEvent->dropAction(), dropTarget.moveDropAction); + } + { + DragEventTester builder; + dropTarget.moveAccept = true; + dropTarget.moveDropAction = Qt::CopyAction; + builder.addEnterEvent(); builder.addMoveEvent(); builder.addLeaveEvent(); + builder.sendDragEventSequence(&window); + QDragMoveEvent* moveEvent = builder.moveEvent; + QCOMPARE(moveEvent->isAccepted(), dropTarget.moveAccept); + QCOMPARE(moveEvent->dropAction(), dropTarget.moveDropAction); + } + + // Test drop events property propagation. + // For drop events, both isAccepted and dropAction get propagated. + dropTarget.reset(); + { + DragEventTester builder; + dropTarget.dropAccept = false; + dropTarget.dropDropAction = Qt::IgnoreAction; + builder.addEnterEvent(); builder.addMoveEvent(); builder.addDropEvent(); + builder.sendDragEventSequence(&window); + QDropEvent* dropEvent = builder.dropEvent; + QCOMPARE(dropEvent->isAccepted(), dropTarget.dropAccept); + QCOMPARE(dropEvent->dropAction(), dropTarget.dropDropAction); + } + { + DragEventTester builder; + dropTarget.dropAccept = false; + dropTarget.dropDropAction = Qt::CopyAction; + builder.addEnterEvent(); builder.addMoveEvent(); builder.addDropEvent(); + builder.sendDragEventSequence(&window); + QDropEvent* dropEvent = builder.dropEvent; + QCOMPARE(dropEvent->isAccepted(), dropTarget.dropAccept); + QCOMPARE(dropEvent->dropAction(), dropTarget.dropDropAction); + } + { + DragEventTester builder; + dropTarget.dropAccept = true; + dropTarget.dropDropAction = Qt::IgnoreAction; + builder.addEnterEvent(); builder.addMoveEvent(); builder.addDropEvent(); + builder.sendDragEventSequence(&window); + QDropEvent* dropEvent = builder.dropEvent; + QCOMPARE(dropEvent->isAccepted(), dropTarget.dropAccept); + QCOMPARE(dropEvent->dropAction(), dropTarget.dropDropAction); + } + { + DragEventTester builder; + dropTarget.dropAccept = true; + dropTarget.dropDropAction = Qt::CopyAction; + builder.addEnterEvent(); builder.addMoveEvent(); builder.addDropEvent(); + builder.sendDragEventSequence(&window); + QDropEvent* dropEvent = builder.dropEvent; + QCOMPARE(dropEvent->isAccepted(), dropTarget.dropAccept); + QCOMPARE(dropEvent->dropAction(), dropTarget.dropDropAction); + } +} + QTEST_MAIN(tst_qquickwindow) #include "tst_qquickwindow.moc" diff --git a/tests/auto/quick/touchmouse/tst_touchmouse.cpp b/tests/auto/quick/touchmouse/tst_touchmouse.cpp index 032e682137..671cefd6f5 100644 --- a/tests/auto/quick/touchmouse/tst_touchmouse.cpp +++ b/tests/auto/quick/touchmouse/tst_touchmouse.cpp @@ -71,7 +71,7 @@ Q_SIGNALS: public: EventItem(QQuickItem *parent = 0) - : QQuickItem(parent), acceptMouse(false), acceptTouch(false), filterTouch(false), point0(-1) + : QQuickItem(parent), touchUngrabCount(0), acceptMouse(false), acceptTouch(false), filterTouch(false), point0(-1) { setAcceptedMouseButtons(Qt::LeftButton); } @@ -111,11 +111,17 @@ public: eventList.append(Event(QEvent::UngrabMouse, QPoint(0,0), QPoint(0,0))); } + void touchUngrabEvent() + { + ++touchUngrabCount; + } + bool event(QEvent *event) { return QQuickItem::event(event); } QList<Event> eventList; + int touchUngrabCount; bool acceptMouse; bool acceptTouch; bool filterTouch; // when used as event filter @@ -158,6 +164,7 @@ private slots: void mouseOverTouch(); void buttonOnFlickable(); + void touchButtonOnFlickable(); void buttonOnDelayedPressFlickable_data(); void buttonOnDelayedPressFlickable(); void buttonOnTouch(); @@ -568,9 +575,10 @@ void tst_TouchMouse::buttonOnFlickable() QCOMPARE(pointerEvent->point(0)->grabber(), eventItem1); QCOMPARE(window->mouseGrabberItem(), eventItem1); - p1 += QPoint(0, -10); - QPoint p2 = p1 + QPoint(0, -10); - QPoint p3 = p2 + QPoint(0, -10); + int dragDelta = -qApp->styleHints()->startDragDistance(); + p1 += QPoint(0, dragDelta); + QPoint p2 = p1 + QPoint(0, dragDelta); + QPoint p3 = p2 + QPoint(0, dragDelta); QQuickTouchUtils::flush(window.data()); QTest::touchEvent(window.data(), device).move(0, p1, window.data()); QQuickTouchUtils::flush(window.data()); @@ -593,6 +601,66 @@ void tst_TouchMouse::buttonOnFlickable() QQuickTouchUtils::flush(window.data()); } +void tst_TouchMouse::touchButtonOnFlickable() +{ + // flickable - height 500 / 1000 + // - eventItem1 y: 100, height 100 + // - eventItem2 y: 300, height 100 + + QScopedPointer<QQuickView> window(createView()); + window->setSource(testFileUrl("buttononflickable.qml")); + window->show(); + QQuickViewTestUtil::centerOnScreen(window.data()); + QVERIFY(QTest::qWaitForWindowActive(window.data())); + QVERIFY(window->rootObject() != 0); + + QQuickFlickable *flickable = window->rootObject()->findChild<QQuickFlickable*>("flickable"); + QVERIFY(flickable); + + EventItem *eventItem2 = window->rootObject()->findChild<EventItem*>("eventItem2"); + QVERIFY(eventItem2); + QCOMPARE(eventItem2->eventList.size(), 0); + eventItem2->acceptTouch = true; + + // press via touch, then drag: check that flickable moves and that the button gets ungrabbed + QCOMPARE(eventItem2->eventList.size(), 0); + QPoint p1 = QPoint(10, 310); + QTest::touchEvent(window.data(), device).press(0, p1, window.data()); + QQuickTouchUtils::flush(window.data()); + QCOMPARE(eventItem2->eventList.size(), 1); + QCOMPARE(eventItem2->eventList.at(0).type, QEvent::TouchBegin); + + QQuickWindowPrivate *windowPriv = QQuickWindowPrivate::get(window.data()); + QVERIFY(windowPriv->touchMouseId == -1); + auto pointerEvent = QQuickPointerDevice::touchDevices().at(0)->pointerEvent(); + QCOMPARE(pointerEvent->point(0)->grabber(), eventItem2); + QCOMPARE(window->mouseGrabberItem(), nullptr); + + int dragDelta = qApp->styleHints()->startDragDistance() * -0.7; + p1 += QPoint(0, dragDelta); + QPoint p2 = p1 + QPoint(0, dragDelta); + QPoint p3 = p2 + QPoint(0, dragDelta); + + QQuickTouchUtils::flush(window.data()); + QTest::touchEvent(window.data(), device).move(0, p1, window.data()); + QQuickTouchUtils::flush(window.data()); + QTest::touchEvent(window.data(), device).move(0, p2, window.data()); + QQuickTouchUtils::flush(window.data()); + QTest::touchEvent(window.data(), device).move(0, p3, window.data()); + QQuickTouchUtils::flush(window.data()); + + QVERIFY(eventItem2->eventList.size() > 2); + QCOMPARE(eventItem2->eventList.at(1).type, QEvent::TouchUpdate); + QCOMPARE(eventItem2->touchUngrabCount, 1); + QCOMPARE(window->mouseGrabberItem(), flickable); + QVERIFY(windowPriv->touchMouseId != -1); + QCOMPARE(pointerEvent->point(0)->grabber(), flickable); + QVERIFY(flickable->isMovingVertically()); + + QTest::touchEvent(window.data(), device).release(0, p3, window.data()); + QQuickTouchUtils::flush(window.data()); +} + void tst_TouchMouse::buttonOnDelayedPressFlickable_data() { QTest::addColumn<bool>("scrollBeforeDelayIsOver"); diff --git a/tests/auto/toolsupport/tst_toolsupport.cpp b/tests/auto/toolsupport/tst_toolsupport.cpp index 9a11a67e65..526ba8f375 100644 --- a/tests/auto/toolsupport/tst_toolsupport.cpp +++ b/tests/auto/toolsupport/tst_toolsupport.cpp @@ -109,7 +109,7 @@ void tst_toolsupport::offsets_data() = QTest::newRow("CompiledData::CompilationUnit::runtimeStrings") << pmm_to_offsetof(&QV4::CompiledData::CompilationUnit::runtimeStrings); - data << 16 << 32; + data << 12 << 24; } { |