From de74c0ee3eab435f2a95849216129ac8e7043972 Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Wed, 27 Jan 2016 13:11:14 +0100 Subject: Add Popup::closePolicy Change-Id: Ie3d0f50a59aeaab36ec388af897cbf2596269ce3 Reviewed-by: Mitch Curtis --- tests/auto/popup/data/applicationwindow.qml | 65 ++++++++++ tests/auto/popup/popup.pro | 14 +++ tests/auto/popup/tst_popup.cpp | 184 ++++++++++++++++++++++++++++ 3 files changed, 263 insertions(+) create mode 100644 tests/auto/popup/data/applicationwindow.qml create mode 100644 tests/auto/popup/popup.pro create mode 100644 tests/auto/popup/tst_popup.cpp (limited to 'tests/auto/popup') 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 +#include +#include "../shared/util.h" +#include "../shared/visualtestutil.h" + +#include +#include +#include + +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(); + 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(); + 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(); + + QTest::addColumn("closePolicy"); + + QTest::newRow("NoAutoClose") << static_cast(QQuickPopup::NoAutoClose); + QTest::newRow("OnPressOutside") << static_cast(QQuickPopup::OnPressOutside); + QTest::newRow("OnReleaseOutside") << static_cast(QQuickPopup::OnReleaseOutside); + QTest::newRow("OnEscape") << static_cast(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(); + 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" -- cgit v1.2.3