aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/popup
diff options
context:
space:
mode:
authorMitch Curtis <mitch.curtis@qt.io>2017-05-26 16:11:17 +0200
committerMitch Curtis <mitch.curtis@qt.io>2017-05-26 19:23:31 +0000
commit8bf206d58b20b6f0e7f60f46c167e7d689b10e5e (patch)
treef17a3235bbd4aa4591e334ca72ba837cd20bea70 /tests/auto/popup
parent5d84ae4cd94c1680900e2f1018b23fd2d484eef3 (diff)
tst_popup: add closeOnEscapeWithNestedPopups()
This test confirms that the behavior found in the gallery example (where there are several nested popups that should close when the Escape key is pressed, and a Shortcut that should also be activated by the Escape key once all popups are closed) continues to work. Change-Id: Ie848ff3505e66ded7b78777808d982c642092d61 Reviewed-by: J-P Nurmi <jpnurmi@qt.io>
Diffstat (limited to 'tests/auto/popup')
-rw-r--r--tests/auto/popup/data/closeOnEscapeWithNestedPopups.qml112
-rw-r--r--tests/auto/popup/tst_popup.cpp68
2 files changed, 180 insertions, 0 deletions
diff --git a/tests/auto/popup/data/closeOnEscapeWithNestedPopups.qml b/tests/auto/popup/data/closeOnEscapeWithNestedPopups.qml
new file mode 100644
index 00000000..53dae0f9
--- /dev/null
+++ b/tests/auto/popup/data/closeOnEscapeWithNestedPopups.qml
@@ -0,0 +1,112 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 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.9
+import QtQuick.Controls 2.2
+
+ApplicationWindow {
+ width: 400
+ height: 400
+
+ header: ToolBar {
+ ToolButton {
+ objectName: "optionsToolButton"
+ text: "Options"
+ onClicked: optionsMenu.open()
+
+ Menu {
+ id: optionsMenu
+ objectName: "optionsMenu"
+ x: parent.width - width
+ transformOrigin: Menu.TopRight
+
+ MenuItem {
+ objectName: "settingsMenuItem"
+ text: "Settings"
+ onTriggered: settingsDialog.open()
+ }
+ }
+ }
+ }
+
+ Shortcut {
+ sequence: "Esc"
+ enabled: stackView.depth > 1
+ onActivated: stackView.pop()
+ }
+
+ Component {
+ id: itemComponent
+
+ Item {}
+ }
+
+ StackView {
+ id: stackView
+ objectName: "stackView"
+ anchors.fill: parent
+ initialItem: Item {
+ objectName: "initialStackViewItem"
+ }
+
+ Component.onCompleted: push(itemComponent)
+ }
+
+ Dialog {
+ id: settingsDialog
+ objectName: "settingsDialog"
+ modal: true
+
+ contentItem: ComboBox {
+ objectName: "comboBox"
+ model: 10
+ }
+ }
+}
diff --git a/tests/auto/popup/tst_popup.cpp b/tests/auto/popup/tst_popup.cpp
index 9001c3ee..1b4f0aca 100644
--- a/tests/auto/popup/tst_popup.cpp
+++ b/tests/auto/popup/tst_popup.cpp
@@ -41,10 +41,12 @@
#include <QtGui/qpa/qwindowsysteminterface.h>
#include <QtQuickTemplates2/private/qquickapplicationwindow_p.h>
+#include <QtQuickTemplates2/private/qquickcombobox_p.h>
#include <QtQuickTemplates2/private/qquickoverlay_p.h>
#include <QtQuickTemplates2/private/qquickpopup_p.h>
#include <QtQuickTemplates2/private/qquickbutton_p.h>
#include <QtQuickTemplates2/private/qquickslider_p.h>
+#include <QtQuickTemplates2/private/qquickstackview_p.h>
using namespace QQuickVisualTestUtil;
@@ -76,6 +78,7 @@ private slots:
void grabber();
void cursorShape();
void componentComplete();
+ void closeOnEscapeWithNestedPopups();
};
void tst_popup::initTestCase()
@@ -838,6 +841,71 @@ void tst_popup::componentComplete()
QVERIFY(qmlPopup->isComponentComplete());
}
+void tst_popup::closeOnEscapeWithNestedPopups()
+{
+ // Tests the scenario in the Gallery example, where there are nested popups that should
+ // close in the correct order when the Escape key is pressed.
+ QQuickApplicationHelper helper(this, QStringLiteral("closeOnEscapeWithNestedPopups.qml"));
+ QQuickApplicationWindow *window = helper.appWindow;
+ window->show();
+ QVERIFY(QTest::qWaitForWindowExposed(window));
+
+ // The stack view should have two items, and it should pop the second when escape is pressed
+ // and it has focus.
+ QQuickStackView *stackView = window->findChild<QQuickStackView*>("stackView");
+ QVERIFY(stackView);
+ QCOMPARE(stackView->depth(), 2);
+
+ QQuickItem *optionsToolButton = window->findChild<QQuickItem*>("optionsToolButton");
+ QVERIFY(optionsToolButton);
+
+ // Click on the options tool button. The settings menu should pop up.
+ const QPoint optionsToolButtonCenter = optionsToolButton->mapToScene(
+ QPointF(optionsToolButton->width() / 2, optionsToolButton->height() / 2)).toPoint();
+ QTest::mouseClick(window, Qt::LeftButton, Qt::NoModifier, optionsToolButtonCenter);
+
+ QQuickPopup *optionsMenu = window->findChild<QQuickPopup*>("optionsMenu");
+ QVERIFY(optionsMenu);
+ QTRY_VERIFY(optionsMenu->isVisible());
+
+ QQuickItem *settingsMenuItem = window->findChild<QQuickItem*>("settingsMenuItem");
+ QVERIFY(settingsMenuItem);
+
+ // Click on the settings menu item. The settings dialog should pop up.
+ const QPoint settingsMenuItemCenter = settingsMenuItem->mapToScene(
+ QPointF(settingsMenuItem->width() / 2, settingsMenuItem->height() / 2)).toPoint();
+ QTest::mouseClick(window, Qt::LeftButton, Qt::NoModifier, settingsMenuItemCenter);
+
+ QQuickPopup *settingsDialog = window->contentItem()->findChild<QQuickPopup*>("settingsDialog");
+ QVERIFY(settingsDialog);
+ QTRY_VERIFY(settingsDialog->isVisible());
+
+ QQuickComboBox *comboBox = window->contentItem()->findChild<QQuickComboBox*>("comboBox");
+ QVERIFY(comboBox);
+
+ // Click on the combo box button. The combo box popup should pop up.
+ const QPoint comboBoxCenter = comboBox->mapToScene(
+ QPointF(comboBox->width() / 2, comboBox->height() / 2)).toPoint();
+ QTest::mouseClick(window, Qt::LeftButton, Qt::NoModifier, comboBoxCenter);
+ QTRY_VERIFY(comboBox->popup()->isVisible());
+
+ // Close the combo box popup with the escape key. The settings dialog should still be visible.
+ QTest::keyClick(window, Qt::Key_Escape);
+ QTRY_VERIFY(!comboBox->popup()->isVisible());
+ QVERIFY(settingsDialog->isVisible());
+
+ // Close the settings dialog with the escape key.
+ QTest::keyClick(window, Qt::Key_Escape);
+ QTRY_VERIFY(!settingsDialog->isVisible());
+
+ // The stack view should still have two items.
+ QCOMPARE(stackView->depth(), 2);
+
+ // Remove one by pressing the Escape key (the Shortcut should be activated).
+ QTest::keyClick(window, Qt::Key_Escape);
+ QCOMPARE(stackView->depth(), 1);
+}
+
QTEST_MAIN(tst_popup)
#include "tst_popup.moc"