on d2aa4eb help sign in
unity8/tests/plugins/Ubuntu/Gestures/tst_PressedOutsideNotifier.cpp
150 lines 4.3 kB history raw
1/*
2 * Copyright (C) 2013 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 "GestureTest.h"
19#include <PressedOutsideNotifier.h>
21#include <QQuickItem>
22#include <QQuickView>
23#include <QtTest>
25class tst_PressedOutsideNotifier: public GestureTest
27 Q_OBJECT
28public:
29 tst_PressedOutsideNotifier();
30private Q_SLOTS:
31 void init() override; // called right before each and every test function is executed
33 void touchOutsideAreaTriggersSignal();
34 void touchInsideAreaHasNoEffect();
35 void mousePressOutsideAreaTriggersSignal();
36 void mousePresssInsideAreaHasNoEffect();
37 void nothingHappensWhileDisabled();
39private:
40 QQuickItem *m_blueRect;
41 PressedOutsideNotifier *m_notifier;
42};
44tst_PressedOutsideNotifier::tst_PressedOutsideNotifier()
45 : GestureTest(QStringLiteral("tst_PressedOutsideNotifier.qml"))
49void tst_PressedOutsideNotifier::init()
51 GestureTest::init();
53 m_blueRect = m_view->rootObject()->findChild<QQuickItem*>("blueRect");
54 Q_ASSERT(m_blueRect != nullptr);
56 m_notifier =
57 m_view->rootObject()->findChild<PressedOutsideNotifier*>("pressedOutsideNotifier");
58 Q_ASSERT(m_notifier != nullptr);
61void tst_PressedOutsideNotifier::touchOutsideAreaTriggersSignal()
63 // half-way towards the top-left corner of the blueRect.
64 // Therefore, still outside it.
65 QPoint touch0 = QPoint(m_blueRect->x() * 0.5, m_blueRect->y() * 0.5);
67 QSignalSpy pressedOutsideSpy(m_notifier, &PressedOutsideNotifier::pressedOutside);
69 QTest::touchEvent(m_view, m_device)
70 .press(0, touch0);
72 qApp->processEvents();
74 QCOMPARE(pressedOutsideSpy.count(), 1);
76 QTest::touchEvent(m_view, m_device)
77 .release(0, touch0);
80void tst_PressedOutsideNotifier::touchInsideAreaHasNoEffect()
82 QPoint touch0 = QPoint(m_blueRect->x() + m_blueRect->width()*0.5,
83 m_blueRect->y() + m_blueRect->height()*0.5);
85 QSignalSpy pressedOutsideSpy(m_notifier, &PressedOutsideNotifier::pressedOutside);
87 QTest::touchEvent(m_view, m_device)
88 .press(0, touch0);
90 qApp->processEvents();
92 QCOMPARE(pressedOutsideSpy.count(), 0);
94 QTest::touchEvent(m_view, m_device)
95 .release(0, touch0);
98void tst_PressedOutsideNotifier::mousePressOutsideAreaTriggersSignal()
100 QPoint mousePos= QPoint(m_blueRect->x() * 0.5, m_blueRect->y() * 0.5);
102 QSignalSpy pressedOutsideSpy(m_notifier, &PressedOutsideNotifier::pressedOutside);
104 QTest::mousePress(m_view, Qt::LeftButton, 0 /*modifiers*/, mousePos);
106 qApp->processEvents();
108 QCOMPARE(pressedOutsideSpy.count(), 1);
110 QTest::mouseRelease(m_view, Qt::LeftButton, 0 /*modifiers*/, mousePos);
113void tst_PressedOutsideNotifier::mousePresssInsideAreaHasNoEffect()
115 QPoint mousePos = QPoint(m_blueRect->x() + m_blueRect->width()*0.5,
116 m_blueRect->y() + m_blueRect->height()*0.5);
118 QSignalSpy pressedOutsideSpy(m_notifier, &PressedOutsideNotifier::pressedOutside);
120 QTest::mousePress(m_view, Qt::LeftButton, 0 /*modifiers*/, mousePos);
122 qApp->processEvents();
124 QCOMPARE(pressedOutsideSpy.count(), 0);
126 QTest::mouseRelease(m_view, Qt::LeftButton, 0 /*modifiers*/, mousePos);
129void tst_PressedOutsideNotifier::nothingHappensWhileDisabled()
131 QPoint touch0 = QPoint(m_blueRect->x() * 0.5, m_blueRect->y() * 0.5);
133 QSignalSpy pressedOutsideSpy(m_notifier, &PressedOutsideNotifier::pressedOutside);
135 m_notifier->setEnabled(false);
137 QTest::touchEvent(m_view, m_device)
138 .press(0, touch0);
140 qApp->processEvents();
142 QCOMPARE(pressedOutsideSpy.count(), 0);
144 QTest::touchEvent(m_view, m_device)
145 .release(0, touch0);
148QTEST_MAIN(tst_PressedOutsideNotifier)
150#include "tst_PressedOutsideNotifier.moc"