aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@theqtcompany.com>2016-01-27 13:11:14 +0100
committerJ-P Nurmi <jpnurmi@theqtcompany.com>2016-01-28 09:29:22 +0000
commitde74c0ee3eab435f2a95849216129ac8e7043972 (patch)
treeacec13d74c8f170d3f3161f87d87c9342f34aae2 /tests
parent8d8bc174243215715cb0e9143f230158c357ece1 (diff)
Add Popup::closePolicy
Change-Id: Ie3d0f50a59aeaab36ec388af897cbf2596269ce3 Reviewed-by: Mitch Curtis <mitch.curtis@theqtcompany.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/auto.pro1
-rw-r--r--tests/auto/popup/data/applicationwindow.qml65
-rw-r--r--tests/auto/popup/popup.pro14
-rw-r--r--tests/auto/popup/tst_popup.cpp184
4 files changed, 264 insertions, 0 deletions
diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro
index 3b3ee04a..ec9d4111 100644
--- a/tests/auto/auto.pro
+++ b/tests/auto/auto.pro
@@ -7,6 +7,7 @@ SUBDIRS += \
controls \
material \
menu \
+ popup \
pressandhold \
sanity \
snippets \
diff --git a/tests/auto/popup/data/applicationwindow.qml b/tests/auto/popup/data/applicationwindow.qml
new file mode 100644
index 00000000..69cbf47f
--- /dev/null
+++ b/tests/auto/popup/data/applicationwindow.qml
@@ -0,0 +1,65 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** 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.6
+import Qt.labs.controls 1.0
+
+ApplicationWindow {
+ width: 400
+ height: 400
+
+ property alias popup: popup
+
+ Popup {
+ id: popup
+ x: (parent.width - width) / 2
+ y: (parent.height - height) / 2
+
+ Text {
+ color: "white"
+ text: "Hello, world!"
+
+ MouseArea {
+ anchors.fill: parent
+ onClicked: popup.close()
+ }
+ }
+ }
+}
diff --git a/tests/auto/popup/popup.pro b/tests/auto/popup/popup.pro
new file mode 100644
index 00000000..87aca3b3
--- /dev/null
+++ b/tests/auto/popup/popup.pro
@@ -0,0 +1,14 @@
+CONFIG += testcase
+TARGET = tst_popup
+SOURCES += tst_popup.cpp
+
+osx:CONFIG -= app_bundle
+
+QT += core-private gui-private qml-private quick-private testlib labstemplates-private
+
+include (../shared/util.pri)
+
+TESTDATA = data/*
+
+OTHER_FILES += \
+ data/*
diff --git a/tests/auto/popup/tst_popup.cpp b/tests/auto/popup/tst_popup.cpp
new file mode 100644
index 00000000..df73c320
--- /dev/null
+++ b/tests/auto/popup/tst_popup.cpp
@@ -0,0 +1,184 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL3$
+** 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.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPLv3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtTest/qtest.h>
+#include <QtTest/qsignalspy.h>
+#include "../shared/util.h"
+#include "../shared/visualtestutil.h"
+
+#include <QtLabsTemplates/private/qquickapplicationwindow_p.h>
+#include <QtLabsTemplates/private/qquickoverlay_p.h>
+#include <QtLabsTemplates/private/qquickpopup_p_p.h>
+
+using namespace QQuickVisualTestUtil;
+
+class tst_popup : public QQmlDataTest
+{
+ Q_OBJECT
+
+private slots:
+ void visible();
+ void overlay();
+ void closePolicy_data();
+ void closePolicy();
+};
+
+void tst_popup::visible()
+{
+ QQuickApplicationHelper helper(this, QStringLiteral("applicationwindow.qml"));
+
+ QQuickApplicationWindow *window = helper.window;
+ window->show();
+ QVERIFY(QTest::qWaitForWindowActive(window));
+
+ QQuickPopup *popup = helper.window->property("popup").value<QQuickPopup*>();
+ QVERIFY(popup);
+ QQuickItem *popupItem = QQuickPopupPrivate::get(popup)->popupItem;
+
+ popup->open();
+ QVERIFY(popup->isVisible());
+ QVERIFY(window->overlay()->childItems().contains(popupItem));
+
+ popup->close();
+ QVERIFY(!popup->isVisible());
+ QVERIFY(!window->overlay()->childItems().contains(popupItem));
+
+ popup->setVisible(true);
+ QVERIFY(popup->isVisible());
+ QVERIFY(window->overlay()->childItems().contains(popupItem));
+
+ popup->setVisible(false);
+ QVERIFY(!popup->isVisible());
+ QVERIFY(!window->overlay()->childItems().contains(popupItem));
+}
+
+void tst_popup::overlay()
+{
+ QQuickApplicationHelper helper(this, QStringLiteral("applicationwindow.qml"));
+
+ QQuickApplicationWindow *window = helper.window;
+ window->show();
+ QVERIFY(QTest::qWaitForWindowActive(window));
+
+ QQuickItem *overlay = window->overlay();
+ QSignalSpy overlayPressedSignal(overlay, SIGNAL(pressed()));
+ QSignalSpy overlayReleasedSignal(overlay, SIGNAL(released()));
+ QVERIFY(overlayPressedSignal.isValid());
+ QVERIFY(overlayReleasedSignal.isValid());
+
+ QTest::mousePress(window, Qt::LeftButton);
+ QCOMPARE(overlayPressedSignal.count(), 1);
+ QCOMPARE(overlayReleasedSignal.count(), 0);
+
+ QTest::mouseRelease(window, Qt::LeftButton);
+ QCOMPARE(overlayPressedSignal.count(), 1);
+ QCOMPARE(overlayReleasedSignal.count(), 0); // no modal popups open
+
+ QQuickPopup *popup = helper.window->property("popup").value<QQuickPopup*>();
+ QVERIFY(popup);
+
+ popup->setModal(true);
+
+ popup->open();
+ QVERIFY(popup->isVisible());
+
+ QTest::mousePress(window, Qt::LeftButton, Qt::NoModifier, QPoint(popup->x() - 1, popup->y() - 1));
+ QCOMPARE(overlayPressedSignal.count(), 2);
+ QCOMPARE(overlayReleasedSignal.count(), 0);
+
+ QTest::mouseRelease(window, Qt::LeftButton, Qt::NoModifier, QPoint(popup->x() - 1, popup->y() - 1));
+ QCOMPARE(overlayPressedSignal.count(), 2);
+ QCOMPARE(overlayReleasedSignal.count(), 1);
+
+ QTest::mouseClick(window, Qt::LeftButton, Qt::NoModifier, QPoint(popup->x() + popup->width() / 2, popup->y() + popup->height() / 2));
+ QCOMPARE(overlayPressedSignal.count(), 2);
+ QCOMPARE(overlayReleasedSignal.count(), 1);
+ QVERIFY(!popup->isVisible());
+}
+
+Q_DECLARE_METATYPE(QQuickPopup::ClosePolicy)
+
+void tst_popup::closePolicy_data()
+{
+ qRegisterMetaType<QQuickPopup::ClosePolicy>();
+
+ QTest::addColumn<QQuickPopup::ClosePolicy>("closePolicy");
+
+ QTest::newRow("NoAutoClose") << static_cast<QQuickPopup::ClosePolicy>(QQuickPopup::NoAutoClose);
+ QTest::newRow("OnPressOutside") << static_cast<QQuickPopup::ClosePolicy>(QQuickPopup::OnPressOutside);
+ QTest::newRow("OnReleaseOutside") << static_cast<QQuickPopup::ClosePolicy>(QQuickPopup::OnReleaseOutside);
+ QTest::newRow("OnEscape") << static_cast<QQuickPopup::ClosePolicy>(QQuickPopup::OnEscape);
+}
+
+void tst_popup::closePolicy()
+{
+ QFETCH(QQuickPopup::ClosePolicy, closePolicy);
+
+ QQuickApplicationHelper helper(this, QStringLiteral("applicationwindow.qml"));
+
+ QQuickApplicationWindow *window = helper.window;
+ window->show();
+ QVERIFY(QTest::qWaitForWindowActive(window));
+
+ QQuickPopup *popup = helper.window->property("popup").value<QQuickPopup*>();
+ QVERIFY(popup);
+
+ popup->setModal(true);
+ popup->setFocus(true);
+ popup->setClosePolicy(closePolicy);
+
+ popup->open();
+ QVERIFY(popup->isVisible());
+
+ QTest::mousePress(window, Qt::LeftButton, Qt::NoModifier, QPoint(popup->x() - 1, popup->y() - 1));
+ QCOMPARE(popup->isVisible(), !closePolicy.testFlag(QQuickPopup::OnPressOutside));
+
+ popup->open();
+ QVERIFY(popup->isVisible());
+
+ QTest::mouseRelease(window, Qt::LeftButton, Qt::NoModifier, QPoint(popup->x() - 1, popup->y() - 1));
+ QCOMPARE(popup->isVisible(), !closePolicy.testFlag(QQuickPopup::OnReleaseOutside));
+
+ popup->open();
+ QVERIFY(popup->isVisible());
+
+ QTest::keyClick(window, Qt::Key_Escape);
+ QCOMPARE(popup->isVisible(), !closePolicy.testFlag(QQuickPopup::OnEscape));
+}
+
+QTEST_MAIN(tst_popup)
+
+#include "tst_popup.moc"