aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorTomi Korpipaa <tomi.korpipaa@qt.io>2021-10-14 09:16:37 +0300
committerTomi Korpipaa <tomi.korpipaa@qt.io>2021-10-15 15:28:40 +0300
commitfa6c1c72ca18c6a450162b8c2160eb4ef8c53900 (patch)
tree621e32dad1db858c2e534db46c91b46d3265db0b /tests
parent92f20b4f4e498fadd0eff087a30be4f0ccfd3048 (diff)
Fix activeFocus for highest-z popup
If there was no popup with active focus, giving focus to the highest-z popup failed on exiting the previous one. This is identical to the dev version, only in a different module: https://codereview.qt-project.org/c/qt/qtdeclarative/+/376653 Fixes: QTBUG-85956 Change-Id: I6f328abfd2d6379297b97940420789aa80293977 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qquickpopup/data/activeFocusAfterExit.qml79
-rw-r--r--tests/auto/qquickpopup/tst_qquickpopup.cpp50
2 files changed, 129 insertions, 0 deletions
diff --git a/tests/auto/qquickpopup/data/activeFocusAfterExit.qml b/tests/auto/qquickpopup/data/activeFocusAfterExit.qml
new file mode 100644
index 00000000..06b0c068
--- /dev/null
+++ b/tests/auto/qquickpopup/data/activeFocusAfterExit.qml
@@ -0,0 +1,79 @@
+/****************************************************************************
+**
+** Copyright (C) 2021 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.12
+import QtQuick.Controls 2.12
+
+ApplicationWindow {
+ width: 400
+ height: 400
+
+ property alias popup1: popup1
+ property alias popup2: popup2
+ property alias popup3: popup3
+
+ Popup {
+ id: popup1
+ focus: true
+ z: 1
+ }
+
+ Popup {
+ id: popup2
+ focus: false
+ z: 2
+ }
+
+ Popup {
+ id: popup3
+ focus: true
+ z: 3
+ }
+}
diff --git a/tests/auto/qquickpopup/tst_qquickpopup.cpp b/tests/auto/qquickpopup/tst_qquickpopup.cpp
index ede3640c..17a703f0 100644
--- a/tests/auto/qquickpopup/tst_qquickpopup.cpp
+++ b/tests/auto/qquickpopup/tst_qquickpopup.cpp
@@ -73,6 +73,7 @@ private slots:
void activeFocusOnClose2();
void activeFocusOnClose3();
void activeFocusOnClosingSeveralPopups();
+ void activeFocusAfterExit();
void hover_data();
void hover();
void wheel_data();
@@ -728,6 +729,55 @@ void tst_QQuickPopup::activeFocusOnClosingSeveralPopups()
QTRY_COMPARE(button->hasActiveFocus(), true);
}
+void tst_QQuickPopup::activeFocusAfterExit()
+{
+ // Test that after closing a popup the highest one in z-order receives it instead.
+ QQuickApplicationHelper helper(this, QStringLiteral("activeFocusAfterExit.qml"));
+ QVERIFY2(helper.ready, helper.failureMessage());
+ QQuickApplicationWindow *window = helper.appWindow;
+ window->show();
+ window->requestActivate();
+ QVERIFY(QTest::qWaitForWindowActive(window));
+
+ QQuickPopup *popup1 = window->property("popup1").value<QQuickPopup*>();
+ QVERIFY(popup1);
+
+ QQuickPopup *popup2 = window->property("popup2").value<QQuickPopup*>();
+ QVERIFY(popup2);
+ QSignalSpy closedSpy2(popup2, SIGNAL(closed()));
+ QVERIFY(closedSpy2.isValid());
+
+ QQuickPopup *popup3 = window->property("popup3").value<QQuickPopup*>();
+ QVERIFY(popup3);
+ QSignalSpy closedSpy3(popup3, SIGNAL(closed()));
+ QVERIFY(closedSpy3.isValid());
+
+ popup1->open();
+ QVERIFY(popup1->isVisible());
+ QTRY_VERIFY(popup1->hasActiveFocus());
+
+ popup2->open();
+ QVERIFY(popup2->isVisible());
+ QTRY_VERIFY(!popup2->hasActiveFocus());
+
+ popup3->open();
+ QVERIFY(popup3->isVisible());
+ QTRY_VERIFY(popup3->hasActiveFocus());
+
+ popup3->close();
+ closedSpy3.wait();
+ QVERIFY(!popup3->isVisible());
+ QTRY_VERIFY(!popup3->hasActiveFocus());
+ QTRY_VERIFY(!popup2->hasActiveFocus());
+ QTRY_VERIFY(popup1->hasActiveFocus());
+
+ popup2->close();
+ closedSpy2.wait();
+ QVERIFY(!popup2->isVisible());
+ QTRY_VERIFY(!popup2->hasActiveFocus());
+ QTRY_VERIFY(popup1->hasActiveFocus());
+}
+
void tst_QQuickPopup::hover_data()
{
QTest::addColumn<QString>("source");