diff options
Diffstat (limited to 'tests/auto/quick/qquickdroparea')
-rw-r--r-- | tests/auto/quick/qquickdroparea/data/nested1.qml | 93 | ||||
-rw-r--r-- | tests/auto/quick/qquickdroparea/data/nested2.qml | 93 | ||||
-rw-r--r-- | tests/auto/quick/qquickdroparea/qquickdroparea.pro | 7 | ||||
-rw-r--r-- | tests/auto/quick/qquickdroparea/tst_qquickdroparea.cpp | 88 |
4 files changed, 267 insertions, 14 deletions
diff --git a/tests/auto/quick/qquickdroparea/data/nested1.qml b/tests/auto/quick/qquickdroparea/data/nested1.qml new file mode 100644 index 0000000000..de6ac70d08 --- /dev/null +++ b/tests/auto/quick/qquickdroparea/data/nested1.qml @@ -0,0 +1,93 @@ +/**************************************************************************** +** +** Copyright (C) 2019 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:BSD$ +** 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 https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +import QtQuick 2.0 + +Item { + width: 200; height: 200 + property int outerEnterEvents: 0 + property int outerExitEvents: 0 + property int innerEnterEvents: 0 + property int innerExitEvents: 0 + + DropArea { + objectName: "outerDropArea" + x: 75; y: 75 + width: 100; height: 100 + Rectangle { + anchors.fill: parent + color: "green" + } + onEntered: ++outerEnterEvents + onExited: ++outerExitEvents + + DropArea { + objectName: "innerDropArea" + width: 50; height: 50 + Rectangle { + anchors.fill: parent + color: "blue" + } + onEntered: ++innerEnterEvents + onExited: ++innerExitEvents + } + } + + Rectangle { + width: 20; height: 20 + color: dragArea.pressed ? "red" : "brown" + Drag.active: dragArea.drag.active + MouseArea { + id: dragArea + objectName: "dragArea" + anchors.fill: parent + drag.target: parent + } + } +} diff --git a/tests/auto/quick/qquickdroparea/data/nested2.qml b/tests/auto/quick/qquickdroparea/data/nested2.qml new file mode 100644 index 0000000000..93630c3779 --- /dev/null +++ b/tests/auto/quick/qquickdroparea/data/nested2.qml @@ -0,0 +1,93 @@ +/**************************************************************************** +** +** Copyright (C) 2019 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:BSD$ +** 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 https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +import QtQuick 2.0 + +Item { + width: 200; height: 200 + property int outerEnterEvents: 0 + property int outerExitEvents: 0 + property int innerEnterEvents: 0 + property int innerExitEvents: 0 + + Rectangle { + x: 75; y: 75 + width: 100; height: 100 + color: "green" + DropArea { + objectName: "outerDropArea" + anchors.fill: parent + onEntered: ++outerEnterEvents + onExited: ++outerExitEvents + } + + Rectangle { + width: 50; height: 50 + color: "blue" + DropArea { + objectName: "innerDropArea" + anchors.fill: parent + onEntered: ++innerEnterEvents + onExited: ++innerExitEvents + } + } + } + + Rectangle { + width: 20; height: 20 + color: dragArea.pressed ? "red" : "brown" + Drag.active: dragArea.drag.active + MouseArea { + id: dragArea + objectName: "dragArea" + anchors.fill: parent + drag.target: parent + } + } +} diff --git a/tests/auto/quick/qquickdroparea/qquickdroparea.pro b/tests/auto/quick/qquickdroparea/qquickdroparea.pro index a34d5ad009..7a8fdef7b9 100644 --- a/tests/auto/quick/qquickdroparea/qquickdroparea.pro +++ b/tests/auto/quick/qquickdroparea/qquickdroparea.pro @@ -4,4 +4,11 @@ macx:CONFIG -= app_bundle SOURCES += tst_qquickdroparea.cpp +OTHER_FILES += $$files(data/*.qml) + +include (../../shared/util.pri) +include (../shared/util.pri) + +TESTDATA = data/* + QT += core-private gui-private qml-private quick-private network testlib diff --git a/tests/auto/quick/qquickdroparea/tst_qquickdroparea.cpp b/tests/auto/quick/qquickdroparea/tst_qquickdroparea.cpp index cf01cc927b..dcba4c872e 100644 --- a/tests/auto/quick/qquickdroparea/tst_qquickdroparea.cpp +++ b/tests/auto/quick/qquickdroparea/tst_qquickdroparea.cpp @@ -28,6 +28,7 @@ #include <QtTest/QtTest> #include <QtTest/QSignalSpy> +#include <QtGui/qstylehints.h> #include <QtQuick/qquickitem.h> #include <QtQuick/qquickview.h> #include <QtQml/qqmlcontext.h> @@ -36,6 +37,8 @@ #include <qpa/qplatformdrag.h> #include <qpa/qwindowsysteminterface.h> +#include "../../shared/util.h" +#include "../shared/viewtestutil.h" template <typename T> static T evaluate(QObject *scope, const QString &expression) { @@ -54,13 +57,10 @@ template <> void evaluate<void>(QObject *scope, const QString &expression) qWarning() << expr.error().toString(); } -class tst_QQuickDropArea: public QObject +class tst_QQuickDropArea: public QQmlDataTest { Q_OBJECT private slots: - void initTestCase(); - void cleanupTestCase(); - void containsDrag_internal(); void containsDrag_external(); void keys_internal(); @@ -74,21 +74,13 @@ private slots: void competingDrags(); void simultaneousDrags(); void dropStuff(); + void nestedDropAreas_data(); + void nestedDropAreas(); private: QQmlEngine engine; }; -void tst_QQuickDropArea::initTestCase() -{ - -} - -void tst_QQuickDropArea::cleanupTestCase() -{ - -} - void tst_QQuickDropArea::containsDrag_internal() { QQuickWindow window; @@ -1224,6 +1216,74 @@ void tst_QQuickDropArea::dropStuff() QCOMPARE(evaluate<QByteArray>(dropArea, "array"), QByteArray("red")); } +void tst_QQuickDropArea::nestedDropAreas_data() +{ + QTest::addColumn<QString>("qmlFile"); + + QTest::newRow("dropRectDropRect") << "nested1.qml"; + QTest::newRow("rectDropRectDrop") << "nested2.qml"; +} + +void tst_QQuickDropArea::nestedDropAreas() +{ + QFETCH(QString, qmlFile); + + const int dragThreshold = QGuiApplication::styleHints()->startDragDistance(); + QQuickView window; + QByteArray errorMessage; + QVERIFY2(QQuickTest::initView(window, testFileUrl(qmlFile.toLatin1().data()), true, &errorMessage), errorMessage.constData()); + + window.show(); + QVERIFY(QTest::qWaitForWindowExposed(&window)); + QVERIFY(window.rootObject() != nullptr); + + QQuickItem *dragArea = window.rootObject()->findChild<QQuickItem*>("dragArea"); + QVERIFY(dragArea); + QQuickItem *outerDropArea = window.rootObject()->findChild<QQuickItem*>("outerDropArea"); + QVERIFY(outerDropArea); + QQuickItem *innerDropArea = window.rootObject()->findChild<QQuickItem*>("innerDropArea"); + QVERIFY(innerDropArea); + + QPoint p = QPoint(10,10); + QTest::mousePress(&window, Qt::LeftButton, Qt::NoModifier, p); + + // move the minimum distance to activate drag + p += QPoint(dragThreshold + 1, dragThreshold + 1); + QTest::mouseMove(&window, p); + + // drag the red rectangle into the inner DropArea + p += QPoint(100, 100); + QTest::mouseMove(&window, p); + QCOMPARE(window.rootObject()->property("outerEnterEvents"), 0); + QCOMPARE(window.rootObject()->property("outerExitEvents"), 0); + QCOMPARE(window.rootObject()->property("innerEnterEvents"), 1); + QCOMPARE(window.rootObject()->property("innerExitEvents"), 0); + + // drag the red rectangle into the outer DropArea + p += QPoint(0, 50); + QTest::mouseMove(&window, p); + QCOMPARE(window.rootObject()->property("outerEnterEvents"), 1); + QCOMPARE(window.rootObject()->property("outerExitEvents"), 0); + QCOMPARE(window.rootObject()->property("innerEnterEvents"), 1); + QCOMPARE(window.rootObject()->property("innerExitEvents"), 1); + + // drag the red rectangle into the inner DropArea + p -= QPoint(0, 50); + QTest::mouseMove(&window, p); + QCOMPARE(window.rootObject()->property("outerEnterEvents"), 1); + QCOMPARE(window.rootObject()->property("outerExitEvents"), 1); + QCOMPARE(window.rootObject()->property("innerEnterEvents"), 2); + QCOMPARE(window.rootObject()->property("innerExitEvents"), 1); + + // drag the red rectangle back out of both + p -= QPoint(100, 100); + QTest::mouseMove(&window, p); + QCOMPARE(window.rootObject()->property("outerEnterEvents"), 1); + QCOMPARE(window.rootObject()->property("outerExitEvents"), 1); + QCOMPARE(window.rootObject()->property("innerEnterEvents"), 2); + QCOMPARE(window.rootObject()->property("innerExitEvents"), 2); +} + QTEST_MAIN(tst_QQuickDropArea) #include "tst_qquickdroparea.moc" |