on d2aa4eb help sign in
unity8/tests/plugins/Ubuntu/Gestures/tst_FloatingFlickable.cpp
122 lines 3.8 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// Ubuntu.Gestures plugin
21#include <DirectionalDragArea.h>
22#include <FloatingFlickable.h>
24#include "GestureTest.h"
25#include "TestItem.h"
27using namespace UbuntuGestures;
29class tst_FloatingFlickable: public GestureTest
31 Q_OBJECT
32public:
33 tst_FloatingFlickable();
34private Q_SLOTS:
35 void tapGoesThrough();
36 void flickChangesContentX();
37 void flickChangesContentY();
38};
40tst_FloatingFlickable::tst_FloatingFlickable()
41 : GestureTest(QStringLiteral("tst_FloatingFlickable.qml"))
45void tst_FloatingFlickable::tapGoesThrough()
47 FloatingFlickable *floatingFlickable =
48 m_view->rootObject()->findChild<FloatingFlickable*>("floatingFlickable");
49 QVERIFY(floatingFlickable != nullptr);
51 TestItem *testItem = new TestItem;
52 testItem->setWidth(floatingFlickable->width());
53 testItem->setHeight(floatingFlickable->height());
54 testItem->setParentItem(m_view->rootObject());
55 testItem->setZ(1.0);
57 floatingFlickable->setZ(2.0);
59 QTest::touchEvent(m_view, m_device)
60 .press(0, QPoint(floatingFlickable->width()/2, floatingFlickable->height()/2));
62 QCOMPARE(testItem->touchEventsReceived.count(), 1);
65void tst_FloatingFlickable::flickChangesContentX()
67 FloatingFlickable *floatingFlickable =
68 m_view->rootObject()->findChild<FloatingFlickable*>("floatingFlickable");
69 QVERIFY(floatingFlickable != nullptr);
71 floatingFlickable->m_dragArea->removeTimeConstraints();
73 qreal startContentX = floatingFlickable->contentX();
75 QPoint startPos(floatingFlickable->width() - 5, 10);
76 int stepCount = 20;
77 int step = (startPos.x() - 5) / stepCount;
79 QTest::touchEvent(m_view, m_device).press(0, startPos);
80 for (int i = 0; i < stepCount; ++i) {
81 QTest::qWait(10);
82 QPoint touchPos = startPos - QPoint(step*i, 0);
83 QTest::touchEvent(m_view, m_device).move(0, touchPos);
84 }
86 QTest::qWait(10);
87 QTest::touchEvent(m_view, m_device).release(0, QPoint(5, 10));
89 QVERIFY(floatingFlickable->contentX() > (startContentX + floatingFlickable->width()/2));
92void tst_FloatingFlickable::flickChangesContentY()
94 FloatingFlickable *floatingFlickable =
95 m_view->rootObject()->findChild<FloatingFlickable*>("floatingFlickable");
96 QVERIFY(floatingFlickable != nullptr);
98 floatingFlickable->setDirection(Direction::Vertical);
99 floatingFlickable->m_dragArea->removeTimeConstraints();
101 qreal startContentY = floatingFlickable->contentY();
103 QPoint startPos(10, floatingFlickable->height() - 5);
104 int stepCount = 20;
105 int step = (startPos.y() - 5) / stepCount;
107 QTest::touchEvent(m_view, m_device).press(0, startPos);
108 for (int i = 0; i < stepCount; ++i) {
109 QTest::qWait(10);
110 QPoint touchPos = startPos - QPoint(0, step*i);
111 QTest::touchEvent(m_view, m_device).move(0, touchPos);
112 }
114 QTest::qWait(10);
115 QTest::touchEvent(m_view, m_device).release(0, QPoint(10, 5));
117 QVERIFY(floatingFlickable->contentY() > (startContentY + floatingFlickable->height()/2));
120QTEST_MAIN(tst_FloatingFlickable)
122#include "tst_FloatingFlickable.moc"