aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp')
-rw-r--r--tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp143
1 files changed, 126 insertions, 17 deletions
diff --git a/tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp b/tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp
index 38253f6ac8..5891e67df6 100644
--- a/tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp
+++ b/tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp
@@ -1,31 +1,26 @@
/****************************************************************************
**
-** Copyright (C) 2015 The Qt Company Ltd.
-** Contact: http://www.qt.io/licensing/
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
**
** This file is part of the test suite of the Qt Toolkit.
**
-** $QT_BEGIN_LICENSE:LGPL21$
+** $QT_BEGIN_LICENSE:GPL-EXCEPT$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://www.qt.io/contact-us.
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 or version 3 as published by the Free
-** Software Foundation and appearing in the file LICENSE.LGPLv21 and
-** LICENSE.LGPLv3 included in the packaging of this file. Please review the
-** following information to ensure the GNU Lesser General Public License
-** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
-** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** As a special exception, The Qt Company gives you certain additional
-** rights. These rights are described in The Qt Company LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
@@ -41,9 +36,11 @@
#include <QtQml/qqmlcontext.h>
#include <QtQml/qqmlengine.h>
#include "../../shared/util.h"
+#include "../shared/viewtestutil.h"
#include <QtGui/qstylehints.h>
#include <QtGui/QCursor>
#include <QtGui/QScreen>
+#include <qpa/qwindowsysteminterface.h>
// Initialize view, set Url, center in available geometry, move mouse away if desired
static bool initView(QQuickView &v, const QUrl &url, bool moveMouseOut, QByteArray *errorMessage)
@@ -73,7 +70,13 @@ static bool initView(QQuickView &v, const QUrl &url, bool moveMouseOut, QByteArr
class tst_QQuickMouseArea: public QQmlDataTest
{
Q_OBJECT
+public:
+ tst_QQuickMouseArea()
+ : device(nullptr)
+ {}
+
private slots:
+ void initTestCase() Q_DECL_OVERRIDE;
void dragProperties();
void resetDrag();
void dragging_data() { acceptedButton_data(); }
@@ -120,15 +123,27 @@ private slots:
void nestedFlickableStopAtBounds();
void containsPress_data();
void containsPress();
+ void ignoreBySource();
private:
void acceptedButton_data();
void rejectedButton_data();
+ QTouchDevice *device;
};
Q_DECLARE_METATYPE(Qt::MouseButton)
Q_DECLARE_METATYPE(Qt::MouseButtons)
+void tst_QQuickMouseArea::initTestCase()
+{
+ QQmlDataTest::initTestCase();
+ if (!device) {
+ device = new QTouchDevice;
+ device->setType(QTouchDevice::TouchScreen);
+ QWindowSystemInterface::registerTouchDevice(device);
+ }
+}
+
void tst_QQuickMouseArea::acceptedButton_data()
{
QTest::addColumn<Qt::MouseButtons>("acceptedButtons");
@@ -1892,6 +1907,100 @@ void tst_QQuickMouseArea::containsPress()
QCOMPARE(containsPressSpy.count(), 4);
}
+void tst_QQuickMouseArea::ignoreBySource()
+{
+ QQuickView window;
+ QByteArray errorMessage;
+ QVERIFY2(initView(window, testFileUrl("ignoreBySource.qml"), true, &errorMessage), errorMessage.constData());
+ window.show();
+ QVERIFY(QTest::qWaitForWindowExposed(&window));
+ QVERIFY(window.rootObject());
+
+ QQuickItem *root = qobject_cast<QQuickItem*>(window.rootObject());
+ QVERIFY(root);
+
+ QQuickMouseArea *mouseArea = root->findChild<QQuickMouseArea*>("mousearea");
+ QVERIFY(mouseArea);
+
+ QQuickFlickable *flickable = root->findChild<QQuickFlickable*>("flickable");
+ QVERIFY(flickable);
+
+ // MouseArea should grab the press because it's interested in non-synthesized mouse events
+ QTest::mousePress(&window, Qt::LeftButton, 0, QPoint(80, 80));
+ QVERIFY(window.mouseGrabberItem() == mouseArea);
+ // That was a real mouse event
+ QVERIFY(root->property("lastEventSource").toInt() == Qt::MouseEventNotSynthesized);
+
+ // Flickable content should not move
+ QTest::mouseMove(&window,QPoint(69,69));
+ QTest::mouseMove(&window,QPoint(58,58));
+ QTest::mouseMove(&window,QPoint(47,47));
+ QCOMPARE(flickable->contentX(), 0.);
+ QCOMPARE(flickable->contentY(), 0.);
+
+ QTest::mouseRelease(&window, Qt::LeftButton, 0, QPoint(47, 47));
+
+ // Now try touch events and confirm that MouseArea ignores them, while Flickable does its thing
+
+ QTest::touchEvent(&window, device).press(0, QPoint(80, 80), &window);
+ QQuickTouchUtils::flush(&window);
+ QVERIFY(window.mouseGrabberItem() != mouseArea);
+ // That was a fake mouse event
+ QCOMPARE(root->property("lastEventSource").toInt(), int(Qt::MouseEventSynthesizedByQt));
+ QTest::touchEvent(&window, device).move(0, QPoint(69,69), &window);
+ QTest::touchEvent(&window, device).move(0, QPoint(69,69), &window);
+ QTest::touchEvent(&window, device).move(0, QPoint(47,47), &window);
+ QQuickTouchUtils::flush(&window);
+ QCOMPARE(window.mouseGrabberItem(), flickable);
+ QTest::touchEvent(&window, device).release(0, QPoint(47,47), &window);
+ QQuickTouchUtils::flush(&window);
+
+ // Flickable content should have moved
+ QTRY_VERIFY(flickable->contentX() > 1);
+ QVERIFY(flickable->contentY() > 1);
+
+
+ // Now tell the MouseArea to accept only synthesized events, and repeat the tests
+ root->setProperty("allowedSource", Qt::MouseEventSynthesizedByQt);
+ flickable->setContentX(0);
+ flickable->setContentY(0);
+
+
+ // MouseArea should ignore the press because it's interested in synthesized mouse events
+ QTest::mousePress(&window, Qt::LeftButton, 0, QPoint(80, 80));
+ QVERIFY(window.mouseGrabberItem() != mouseArea);
+ // That was a real mouse event
+ QVERIFY(root->property("lastEventSource").toInt() == Qt::MouseEventNotSynthesized);
+
+ // Flickable content should move
+ QTest::mouseMove(&window,QPoint(69,69));
+ QTest::mouseMove(&window,QPoint(58,58));
+ QTest::mouseMove(&window,QPoint(47,47));
+ QTRY_VERIFY(flickable->contentX() > 1);
+ QVERIFY(flickable->contentY() > 1);
+
+ QTest::mouseRelease(&window, Qt::LeftButton, 0, QPoint(47, 47));
+ flickable->setContentX(0);
+ flickable->setContentY(0);
+
+ // Now try touch events and confirm that MouseArea gets them, while Flickable doesn't
+
+ QTest::touchEvent(&window, device).press(0, QPoint(80, 80), &window);
+ QQuickTouchUtils::flush(&window);
+ QCOMPARE(window.mouseGrabberItem(), mouseArea);
+ QTest::touchEvent(&window, device).move(0, QPoint(69,69), &window);
+ QTest::touchEvent(&window, device).move(0, QPoint(69,69), &window);
+ QTest::touchEvent(&window, device).move(0, QPoint(47,47), &window);
+ QQuickTouchUtils::flush(&window);
+ QCOMPARE(window.mouseGrabberItem(), mouseArea);
+ QTest::touchEvent(&window, device).release(0, QPoint(47,47), &window);
+ QQuickTouchUtils::flush(&window);
+
+ // Flickable content should not have moved
+ QCOMPARE(flickable->contentX(), 0.);
+ QCOMPARE(flickable->contentY(), 0.);
+}
+
QTEST_MAIN(tst_QQuickMouseArea)
#include "tst_qquickmousearea.moc"