aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/quick
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@theqtcompany.com>2014-10-31 20:20:43 +0100
committerSimon Hausmann <simon.hausmann@theqtcompany.com>2014-10-31 20:21:09 +0100
commit473ef83dba6976250a1ff27175716aa1af970f2f (patch)
tree922044c8be598f76945af1599196c7f379df280e /tests/auto/quick
parentbeb6667d4e65dfe2ec9e7f554837524416c0f4dc (diff)
parent0704d2be63b484cb579c1507223db3f914b1338a (diff)
Merge remote-tracking branch 'origin/5.4' into dev
Diffstat (limited to 'tests/auto/quick')
-rw-r--r--tests/auto/quick/qquickgridview/tst_qquickgridview.cpp29
-rw-r--r--tests/auto/quick/qquicklistview/tst_qquicklistview.cpp29
-rw-r--r--tests/auto/quick/qquickpathview/tst_qquickpathview.cpp28
-rw-r--r--tests/auto/quick/qquickrepeater/tst_qquickrepeater.cpp28
-rw-r--r--tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp21
-rw-r--r--tests/auto/quick/touchmouse/data/twosiblingitems.qml24
-rw-r--r--tests/auto/quick/touchmouse/tst_touchmouse.cpp83
7 files changed, 232 insertions, 10 deletions
diff --git a/tests/auto/quick/qquickgridview/tst_qquickgridview.cpp b/tests/auto/quick/qquickgridview/tst_qquickgridview.cpp
index 33008a9d1b..99702236ee 100644
--- a/tests/auto/quick/qquickgridview/tst_qquickgridview.cpp
+++ b/tests/auto/quick/qquickgridview/tst_qquickgridview.cpp
@@ -204,6 +204,8 @@ private slots:
void displayMargin();
void negativeDisplayMargin();
+ void jsArrayChange();
+
private:
QList<int> toIntList(const QVariantList &list);
void matchIndexLists(const QVariantList &indexLists, const QList<int> &expectedIndexes);
@@ -6431,6 +6433,33 @@ void tst_QQuickGridView::negativeDisplayMargin()
delete window;
}
+void tst_QQuickGridView::jsArrayChange()
+{
+ QQmlEngine engine;
+ QQmlComponent component(&engine);
+ component.setData("import QtQuick 2.4; GridView {}", QUrl());
+
+ QScopedPointer<QQuickGridView> view(qobject_cast<QQuickGridView *>(component.create()));
+ QVERIFY(!view.isNull());
+
+ QSignalSpy spy(view.data(), SIGNAL(modelChanged()));
+ QVERIFY(spy.isValid());
+
+ QJSValue array1 = engine.newArray(3);
+ QJSValue array2 = engine.newArray(3);
+ for (int i = 0; i < 3; ++i) {
+ array1.setProperty(i, i);
+ array2.setProperty(i, i);
+ }
+
+ view->setModel(QVariant::fromValue(array1));
+ QCOMPARE(spy.count(), 1);
+
+ // no change
+ view->setModel(QVariant::fromValue(array2));
+ QCOMPARE(spy.count(), 1);
+}
+
QTEST_MAIN(tst_QQuickGridView)
#include "tst_qquickgridview.moc"
diff --git a/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp b/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp
index 5122b6aa38..9e8a813d54 100644
--- a/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp
+++ b/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp
@@ -239,6 +239,8 @@ private slots:
void QTBUG_39492_data();
void QTBUG_39492();
+ void jsArrayChange();
+
private:
template <class T> void items(const QUrl &source);
template <class T> void changed(const QUrl &source);
@@ -7945,6 +7947,33 @@ void tst_QQuickListView::QTBUG_39492()
releaseView(window);
}
+void tst_QQuickListView::jsArrayChange()
+{
+ QQmlEngine engine;
+ QQmlComponent component(&engine);
+ component.setData("import QtQuick 2.4; ListView {}", QUrl());
+
+ QScopedPointer<QQuickListView> view(qobject_cast<QQuickListView *>(component.create()));
+ QVERIFY(!view.isNull());
+
+ QSignalSpy spy(view.data(), SIGNAL(modelChanged()));
+ QVERIFY(spy.isValid());
+
+ QJSValue array1 = engine.newArray(3);
+ QJSValue array2 = engine.newArray(3);
+ for (int i = 0; i < 3; ++i) {
+ array1.setProperty(i, i);
+ array2.setProperty(i, i);
+ }
+
+ view->setModel(QVariant::fromValue(array1));
+ QCOMPARE(spy.count(), 1);
+
+ // no change
+ view->setModel(QVariant::fromValue(array2));
+ QCOMPARE(spy.count(), 1);
+}
+
QTEST_MAIN(tst_QQuickListView)
#include "tst_qquicklistview.moc"
diff --git a/tests/auto/quick/qquickpathview/tst_qquickpathview.cpp b/tests/auto/quick/qquickpathview/tst_qquickpathview.cpp
index 0e9994899f..992b2347dd 100644
--- a/tests/auto/quick/qquickpathview/tst_qquickpathview.cpp
+++ b/tests/auto/quick/qquickpathview/tst_qquickpathview.cpp
@@ -139,6 +139,7 @@ private slots:
void changePathDuringRefill();
void nestedinFlickable();
void flickableDelegate();
+ void jsArrayChange();
};
class TestObject : public QObject
@@ -2290,6 +2291,33 @@ void tst_QQuickPathView::flickableDelegate()
QCOMPARE(moveStartedSpy.count(), 0);
}
+void tst_QQuickPathView::jsArrayChange()
+{
+ QQmlEngine engine;
+ QQmlComponent component(&engine);
+ component.setData("import QtQuick 2.4; PathView {}", QUrl());
+
+ QScopedPointer<QQuickPathView> view(qobject_cast<QQuickPathView *>(component.create()));
+ QVERIFY(!view.isNull());
+
+ QSignalSpy spy(view.data(), SIGNAL(modelChanged()));
+ QVERIFY(spy.isValid());
+
+ QJSValue array1 = engine.newArray(3);
+ QJSValue array2 = engine.newArray(3);
+ for (int i = 0; i < 3; ++i) {
+ array1.setProperty(i, i);
+ array2.setProperty(i, i);
+ }
+
+ view->setModel(QVariant::fromValue(array1));
+ QCOMPARE(spy.count(), 1);
+
+ // no change
+ view->setModel(QVariant::fromValue(array2));
+ QCOMPARE(spy.count(), 1);
+}
+
QTEST_MAIN(tst_QQuickPathView)
#include "tst_qquickpathview.moc"
diff --git a/tests/auto/quick/qquickrepeater/tst_qquickrepeater.cpp b/tests/auto/quick/qquickrepeater/tst_qquickrepeater.cpp
index 1396dd4783..258eaee981 100644
--- a/tests/auto/quick/qquickrepeater/tst_qquickrepeater.cpp
+++ b/tests/auto/quick/qquickrepeater/tst_qquickrepeater.cpp
@@ -72,6 +72,7 @@ private slots:
void dynamicModelCrash();
void visualItemModelCrash();
void invalidContextCrash();
+ void jsArrayChange();
};
class TestObject : public QObject
@@ -779,6 +780,33 @@ void tst_QQuickRepeater::invalidContextCrash()
root.reset(0);
}
+void tst_QQuickRepeater::jsArrayChange()
+{
+ QQmlEngine engine;
+ QQmlComponent component(&engine);
+ component.setData("import QtQuick 2.4; Repeater {}", QUrl());
+
+ QScopedPointer<QQuickRepeater> repeater(qobject_cast<QQuickRepeater *>(component.create()));
+ QVERIFY(!repeater.isNull());
+
+ QSignalSpy spy(repeater.data(), SIGNAL(modelChanged()));
+ QVERIFY(spy.isValid());
+
+ QJSValue array1 = engine.newArray(3);
+ QJSValue array2 = engine.newArray(3);
+ for (int i = 0; i < 3; ++i) {
+ array1.setProperty(i, i);
+ array2.setProperty(i, i);
+ }
+
+ repeater->setModel(QVariant::fromValue(array1));
+ QCOMPARE(spy.count(), 1);
+
+ // no change
+ repeater->setModel(QVariant::fromValue(array2));
+ QCOMPARE(spy.count(), 1);
+}
+
QTEST_MAIN(tst_QQuickRepeater)
#include "tst_qquickrepeater.moc"
diff --git a/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp b/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp
index 4829b478e9..4f10b4ce82 100644
--- a/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp
+++ b/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp
@@ -171,6 +171,7 @@ private slots:
void preeditCursorRectangle();
void inputMethodComposing();
+ void cursorRectangleSize_data();
void cursorRectangleSize();
void getText_data();
@@ -3654,12 +3655,28 @@ void tst_qquicktextedit::inputMethodComposing()
QCOMPARE(spy.count(), 8);
}
+void tst_qquicktextedit::cursorRectangleSize_data()
+{
+ QTest::addColumn<bool>("useCursorDelegate");
+
+ QTest::newRow("default cursor") << false;
+ QTest::newRow("custom cursor delegate") << true;
+}
+
void tst_qquicktextedit::cursorRectangleSize()
{
+ QFETCH(bool, useCursorDelegate);
+
QQuickView *window = new QQuickView(testFileUrl("positionAt.qml"));
QVERIFY(window->rootObject() != 0);
QQuickTextEdit *textEdit = qobject_cast<QQuickTextEdit *>(window->rootObject());
+ QQmlComponent cursorDelegate(window->engine());
+ if (useCursorDelegate) {
+ cursorDelegate.setData("import QtQuick 2.0\nRectangle { width:10; height:10; }", QUrl());
+ textEdit->setCursorDelegate(&cursorDelegate);
+ }
+
// make sure cursor rectangle is not at (0,0)
textEdit->setX(10);
textEdit->setY(10);
@@ -3677,6 +3694,10 @@ void tst_qquicktextedit::cursorRectangleSize()
QRectF cursorRectFromItem = textEdit->cursorRectangle();
QRectF cursorRectFromPositionToRectangle = textEdit->positionToRectangle(textEdit->cursorPosition());
+ QVERIFY(cursorRectFromItem.isValid());
+ QVERIFY(cursorRectFromQuery.isValid());
+ QVERIFY(cursorRectFromPositionToRectangle.isValid());
+
// item and input query cursor rectangles match
QCOMPARE(cursorRectFromItem, cursorRectFromQuery);
diff --git a/tests/auto/quick/touchmouse/data/twosiblingitems.qml b/tests/auto/quick/touchmouse/data/twosiblingitems.qml
new file mode 100644
index 0000000000..2bf67b1917
--- /dev/null
+++ b/tests/auto/quick/touchmouse/data/twosiblingitems.qml
@@ -0,0 +1,24 @@
+import QtQuick 2.0
+import Qt.test 1.0
+
+Rectangle {
+ id: root
+ width: 320
+ height: 480
+ color: "green"
+
+ EventItem {
+ id: leftItem
+ objectName: "leftItem"
+ width: root.width / 2
+ height: root.height
+ }
+
+ EventItem {
+ objectName: "rightItem"
+ anchors.left: leftItem.right
+ width: root.width / 2
+ height: root.height
+ }
+}
+
diff --git a/tests/auto/quick/touchmouse/tst_touchmouse.cpp b/tests/auto/quick/touchmouse/tst_touchmouse.cpp
index ab1d214369..8c6e3ffc3e 100644
--- a/tests/auto/quick/touchmouse/tst_touchmouse.cpp
+++ b/tests/auto/quick/touchmouse/tst_touchmouse.cpp
@@ -101,10 +101,13 @@ public:
eventList.append(Event(event->type(), event->pos(), event->globalPos()));
event->setAccepted(acceptMouse);
}
+
+ void mouseUngrabEvent()
+ {
+ eventList.append(Event(QEvent::UngrabMouse, QPoint(0,0), QPoint(0,0)));
+ }
+
bool event(QEvent *event) {
- if (event->type() == QEvent::UngrabMouse) {
- eventList.append(Event(event->type(), QPoint(0,0), QPoint(0,0)));
- }
return QQuickItem::event(event);
}
@@ -156,6 +159,8 @@ private slots:
void tapOnDismissiveTopMouseAreaClicksBottomOne();
+ void touchGrabCausesMouseUngrab();
+
protected:
bool eventFilter(QObject *, QEvent *event)
{
@@ -274,9 +279,10 @@ void tst_TouchMouse::simpleTouchEvent()
QCOMPARE(eventItem1->eventList.at(3).type, QEvent::MouseMove);
QTest::touchEvent(window, device).release(0, p1, window);
QQuickTouchUtils::flush(window);
- QCOMPARE(eventItem1->eventList.size(), 6);
+ QCOMPARE(eventItem1->eventList.size(), 7);
QCOMPARE(eventItem1->eventList.at(4).type, QEvent::TouchEnd);
QCOMPARE(eventItem1->eventList.at(5).type, QEvent::MouseButtonRelease);
+ QCOMPARE(eventItem1->eventList.at(6).type, QEvent::UngrabMouse);
eventItem1->eventList.clear();
// wait to avoid getting a double click event
@@ -289,16 +295,17 @@ void tst_TouchMouse::simpleTouchEvent()
p1 = QPoint(20, 20);
QTest::touchEvent(window, device).press(0, p1, window);
QQuickTouchUtils::flush(window);
- QCOMPARE(eventItem1->eventList.size(), 2);
+ QCOMPARE(eventItem1->eventList.size(), 3);
QCOMPARE(eventItem1->eventList.at(0).type, QEvent::TouchBegin);
QCOMPARE(eventItem1->eventList.at(1).type, QEvent::MouseButtonPress);
+ QCOMPARE(eventItem1->eventList.at(2).type, QEvent::UngrabMouse);
p1 += QPoint(10, 0);
QTest::touchEvent(window, device).move(0, p1, window);
QQuickTouchUtils::flush(window);
- QCOMPARE(eventItem1->eventList.size(), 2);
+ QCOMPARE(eventItem1->eventList.size(), 3);
QTest::touchEvent(window, device).release(0, p1, window);
QQuickTouchUtils::flush(window);
- QCOMPARE(eventItem1->eventList.size(), 2);
+ QCOMPARE(eventItem1->eventList.size(), 3);
eventItem1->eventList.clear();
// wait to avoid getting a double click event
@@ -529,9 +536,10 @@ void tst_TouchMouse::buttonOnFlickable()
QCOMPARE(eventItem1->eventList.at(1).type, QEvent::MouseButtonPress);
QTest::touchEvent(window, device).release(0, p1, window);
QQuickTouchUtils::flush(window);
- QCOMPARE(eventItem1->eventList.size(), 4);
+ QCOMPARE(eventItem1->eventList.size(), 5);
QCOMPARE(eventItem1->eventList.at(2).type, QEvent::TouchEnd);
QCOMPARE(eventItem1->eventList.at(3).type, QEvent::MouseButtonRelease);
+ QCOMPARE(eventItem1->eventList.at(4).type, QEvent::UngrabMouse);
eventItem1->eventList.clear();
// touch button
@@ -739,18 +747,20 @@ void tst_TouchMouse::buttonOnTouch()
QQuickTouchUtils::flush(window);
QTest::touchEvent(window, device).release(0, p1, window);
QQuickTouchUtils::flush(window);
- QCOMPARE(eventItem1->eventList.size(), 4);
+ QCOMPARE(eventItem1->eventList.size(), 5);
QCOMPARE(eventItem1->eventList.at(0).type, QEvent::TouchBegin);
QCOMPARE(eventItem1->eventList.at(1).type, QEvent::MouseButtonPress);
QCOMPARE(eventItem1->eventList.at(2).type, QEvent::TouchEnd);
QCOMPARE(eventItem1->eventList.at(3).type, QEvent::MouseButtonRelease);
+ QCOMPARE(eventItem1->eventList.at(4).type, QEvent::UngrabMouse);
eventItem1->eventList.clear();
// Normal mouse click
QTest::mouseClick(window, Qt::LeftButton, 0, p1);
- QCOMPARE(eventItem1->eventList.size(), 2);
+ QCOMPARE(eventItem1->eventList.size(), 3);
QCOMPARE(eventItem1->eventList.at(0).type, QEvent::MouseButtonPress);
QCOMPARE(eventItem1->eventList.at(1).type, QEvent::MouseButtonRelease);
+ QCOMPARE(eventItem1->eventList.at(2).type, QEvent::UngrabMouse);
eventItem1->eventList.clear();
// Pinch starting on the PinchArea should work
@@ -1169,6 +1179,59 @@ void tst_TouchMouse::tapOnDismissiveTopMouseAreaClicksBottomOne()
delete window;
}
+/*
+ If an item grabs a touch that is currently being used for mouse pointer emulation,
+ the current mouse grabber should lose the mouse as mouse events will no longer
+ be generated from that touch point.
+ */
+void tst_TouchMouse::touchGrabCausesMouseUngrab()
+{
+ QQuickView *window = createView();
+
+ window->setSource(testFileUrl("twosiblingitems.qml"));
+ window->show();
+ QVERIFY(QTest::qWaitForWindowExposed(window));
+ window->requestActivate();
+ QVERIFY(QTest::qWaitForWindowActive(window));
+ QVERIFY(window->rootObject() != 0);
+
+ EventItem *leftItem = window->rootObject()->findChild<EventItem*>("leftItem");
+ QVERIFY(leftItem);
+
+ EventItem *rightItem = window->rootObject()->findChild<EventItem*>("rightItem");
+ QVERIFY(leftItem);
+
+ // Send a touch to the leftItem. But leftItem accepts only mouse events, thus
+ // a mouse event will be synthesized out of this touch and will get accepted by
+ // leftItem.
+ leftItem->acceptMouse = true;
+ leftItem->setAcceptedMouseButtons(Qt::LeftButton);
+ QPoint p1;
+ p1 = QPoint(leftItem->width() / 2, leftItem->height() / 2);
+ QTest::touchEvent(window, device).press(0, p1, window);
+ QQuickTouchUtils::flush(window);
+ QCOMPARE(leftItem->eventList.size(), 2);
+ QCOMPARE(leftItem->eventList.at(0).type, QEvent::TouchBegin);
+ QCOMPARE(leftItem->eventList.at(1).type, QEvent::MouseButtonPress);
+ QCOMPARE(window->mouseGrabberItem(), leftItem);
+ leftItem->eventList.clear();
+
+ rightItem->acceptTouch = true;
+ {
+ QVector<int> ids;
+ ids.append(0);
+ rightItem->grabTouchPoints(ids);
+ }
+
+ // leftItem should have lost the mouse as the touch point that was being used to emulate it
+ // has been grabbed by another item.
+ QCOMPARE(leftItem->eventList.size(), 1);
+ QCOMPARE(leftItem->eventList.at(0).type, QEvent::UngrabMouse);
+ QCOMPARE(window->mouseGrabberItem(), (QQuickItem*)0);
+
+ delete window;
+}
+
QTEST_MAIN(tst_TouchMouse)
#include "tst_touchmouse.moc"