on d3e2ebf help sign in
unity8/tests/plugins/Ubuntu/Gestures/tst_FloatingFlickable.cpp
131 lines 4.3 kB history raw
1/*
2 * Copyright (C) 2015 Canonical, Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
17#include <QtTest>
18#include <QQuickView>
20#include "GestureTest.h"
21#include "TestItem.h"
22#include "Direction.h"
24UG_USE_NAMESPACE
26class tst_FloatingFlickable: public GestureTest
28 Q_OBJECT
29public:
30 tst_FloatingFlickable();
31private Q_SLOTS:
32 void tapGoesThrough();
33 void flickChangesContentX();
34 void flickChangesContentY();
35};
37tst_FloatingFlickable::tst_FloatingFlickable()
38 : GestureTest(QStringLiteral("tst_FloatingFlickable.qml"))
42void tst_FloatingFlickable::tapGoesThrough()
44 QQuickItem *floatingFlickable =
45 m_view->rootObject()->findChild<QQuickItem*>("floatingFlickable");
46 QVERIFY(floatingFlickable != nullptr);
48 TestItem *testItem = new TestItem;
49 testItem->setWidth(floatingFlickable->width());
50 testItem->setHeight(floatingFlickable->height());
51 testItem->setParentItem(m_view->rootObject());
52 testItem->setZ(1.0);
54 floatingFlickable->setZ(2.0);
56 QTest::touchEvent(m_view, m_device)
57 .press(0, QPoint(floatingFlickable->width()/2, floatingFlickable->height()/2));
59 QCOMPARE(testItem->touchEventsReceived.count(), 1);
62static void removeTimeConstraints(QQuickItem *floatingFlickable)
64 auto children = floatingFlickable->findChildren<QObject*>();
65 Q_FOREACH(QObject *child, children) {
66 if (child->metaObject()->className() == QByteArray("UCSwipeAreaPrivate")) {
67 QMetaObject::invokeMethod(child, "setMaxTime", Q_ARG(int, 60 * 60 * 1000));
68 QMetaObject::invokeMethod(child, "setCompositionTime", Q_ARG(int, 0));
69 }
70 }
73void tst_FloatingFlickable::flickChangesContentX()
75 QSKIP("This fails due to bug #1564571");
76 QQuickItem *floatingFlickable =
77 m_view->rootObject()->findChild<QQuickItem*>("floatingFlickable");
78 QVERIFY(floatingFlickable != nullptr);
79 removeTimeConstraints(floatingFlickable);
81 qreal startContentX = floatingFlickable->property("contentX").toReal();
83 QPoint startPos(floatingFlickable->width() - 5, 10);
84 int stepCount = 20;
85 int step = (startPos.x() - 5) / stepCount;
87 QTest::touchEvent(m_view, m_device).press(0, startPos);
88 for (int i = 0; i < stepCount; ++i) {
89 QTest::qWait(10);
90 QPoint touchPos = startPos - QPoint(step*i, 0);
91 QTest::touchEvent(m_view, m_device).move(0, touchPos);
92 }
94 QTest::qWait(10);
95 QTest::touchEvent(m_view, m_device).release(0, QPoint(5, 10));
97 QVERIFY(floatingFlickable->property("contentX").toReal() > (startContentX + floatingFlickable->width()/2));
100void tst_FloatingFlickable::flickChangesContentY()
102 QSKIP("This fails due to bug #1564571");
103 QQuickItem *floatingFlickable =
104 m_view->rootObject()->findChild<QQuickItem*>("floatingFlickable");
105 QVERIFY(floatingFlickable != nullptr);
107 floatingFlickable->setProperty("direction", Direction::Vertical);
108 removeTimeConstraints(floatingFlickable);
110 qreal startContentY = floatingFlickable->property("contentY").toReal();
112 QPoint startPos(10, floatingFlickable->height() - 5);
113 int stepCount = 20;
114 int step = (startPos.y() - 5) / stepCount;
116 QTest::touchEvent(m_view, m_device).press(0, startPos);
117 for (int i = 0; i < stepCount; ++i) {
118 QTest::qWait(10);
119 QPoint touchPos = startPos - QPoint(0, step*i);
120 QTest::touchEvent(m_view, m_device).move(0, touchPos);
121 }
123 QTest::qWait(10);
124 QTest::touchEvent(m_view, m_device).release(0, QPoint(10, 5));
126 QVERIFY(floatingFlickable->property("contentY").toReal() > (startContentY + floatingFlickable->height()/2));
129QTEST_MAIN(tst_FloatingFlickable)
131#include "tst_FloatingFlickable.moc"