@@ -0,0 +1,150 @@
2+ * Copyright (C) 2013 Canonical, Ltd.
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.
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.
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/>.
17+#include "GestureTest.h"
19+#include <PressedOutsideNotifier.h>
25+class tst_PressedOutsideNotifier: public GestureTest
29+ tst_PressedOutsideNotifier();
31+ void init(); // 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();
40+ QQuickItem *m_blueRect;
41+ PressedOutsideNotifier *m_notifier;
44+tst_PressedOutsideNotifier::tst_PressedOutsideNotifier()
45+ : GestureTest(QStringLiteral("tst_PressedOutsideNotifier.qml"))
49+void tst_PressedOutsideNotifier::init()
53+ m_blueRect = m_view->rootObject()->findChild<QQuickItem*>("blueRect");
54+ Q_ASSERT(m_blueRect != nullptr);
57+ m_view->rootObject()->findChild<PressedOutsideNotifier*>("pressedOutsideNotifier");
58+ Q_ASSERT(m_notifier != nullptr);
61+void 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, SIGNAL(pressedOutside()));
69+ QTest::touchEvent(m_view, m_device)
72+ qApp->processEvents();
74+ QCOMPARE(pressedOutsideSpy.count(), 1);
76+ QTest::touchEvent(m_view, m_device)
80+void 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, SIGNAL(pressedOutside()));
87+ QTest::touchEvent(m_view, m_device)
90+ qApp->processEvents();
92+ QCOMPARE(pressedOutsideSpy.count(), 0);
94+ QTest::touchEvent(m_view, m_device)
98+void tst_PressedOutsideNotifier::mousePressOutsideAreaTriggersSignal()
100+ QPoint mousePos= QPoint(m_blueRect->x() * 0.5, m_blueRect->y() * 0.5);
102+ QSignalSpy pressedOutsideSpy(m_notifier, SIGNAL(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);
113+void 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, SIGNAL(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);
129+void tst_PressedOutsideNotifier::nothingHappensWhileDisabled()
131+ QPoint touch0 = QPoint(m_blueRect->x() * 0.5, m_blueRect->y() * 0.5);
133+ QSignalSpy pressedOutsideSpy(m_notifier, SIGNAL(pressedOutside()));
135+ m_notifier->setEnabled(false);
137+ QTest::touchEvent(m_view, m_device)
140+ qApp->processEvents();
142+ QCOMPARE(pressedOutsideSpy.count(), 0);
144+ QTest::touchEvent(m_view, m_device)
145+ .release(0, touch0);
148+QTEST_MAIN(tst_PressedOutsideNotifier)
150+#include "tst_PressedOutsideNotifier.moc"