aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/quickcontrols2/qquickpopup/tst_qquickpopup.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/quickcontrols2/qquickpopup/tst_qquickpopup.cpp')
-rw-r--r--tests/auto/quickcontrols2/qquickpopup/tst_qquickpopup.cpp149
1 files changed, 124 insertions, 25 deletions
diff --git a/tests/auto/quickcontrols2/qquickpopup/tst_qquickpopup.cpp b/tests/auto/quickcontrols2/qquickpopup/tst_qquickpopup.cpp
index 87667989a2..44299d674f 100644
--- a/tests/auto/quickcontrols2/qquickpopup/tst_qquickpopup.cpp
+++ b/tests/auto/quickcontrols2/qquickpopup/tst_qquickpopup.cpp
@@ -31,6 +31,8 @@
#include <QtCore/qoperatingsystemversion.h>
#include <QtGui/qpa/qwindowsysteminterface.h>
+#include <QtGui/qpa/qplatformintegration.h>
+#include <QtGui/private/qguiapplication_p.h>
#include <QtQuick/qquickview.h>
#include <QtQuick/private/qquickpalette_p.h>
#include <QtQuickTestUtils/private/qmlutils_p.h>
@@ -71,6 +73,8 @@ private slots:
void windowChange();
void closePolicy_data();
void closePolicy();
+ void closePolicy_grabberInside_data();
+ void closePolicy_grabberInside();
void activeFocusOnClose1();
void activeFocusOnClose2();
void activeFocusOnClose3();
@@ -106,6 +110,9 @@ private slots:
void dimmerContainmentMask();
void shrinkPopupThatWasLargerThanWindow_data();
void shrinkPopupThatWasLargerThanWindow();
+
+private:
+ static bool hasWindowActivation();
};
tst_QQuickPopup::tst_QQuickPopup()
@@ -126,6 +133,11 @@ void tst_QQuickPopup::visible_data()
QTest::newRow("ApplicationWindow") << "applicationwindow.qml";
}
+bool tst_QQuickPopup::hasWindowActivation()
+{
+ return (QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::WindowActivation));
+}
+
void tst_QQuickPopup::visible()
{
QFETCH(QString, source);
@@ -134,8 +146,7 @@ void tst_QQuickPopup::visible()
QQuickWindow *window = helper.window;
window->show();
- window->requestActivate();
- QVERIFY(QTest::qWaitForWindowActive(window));
+ QVERIFY(QTest::qWaitForWindowExposed(window));
QQuickPopup *popup = window->property("popup").value<QQuickPopup*>();
QVERIFY(popup);
@@ -231,8 +242,7 @@ void tst_QQuickPopup::overlay()
QQuickWindow *window = helper.window;
window->show();
- window->requestActivate();
- QVERIFY(QTest::qWaitForWindowActive(window));
+ QVERIFY(QTest::qWaitForWindowExposed(window));
QQuickOverlay *overlay = QQuickOverlay::overlay(window);
QVERIFY(overlay);
@@ -383,8 +393,7 @@ void tst_QQuickPopup::zOrder()
QQuickWindow *window = helper.window;
window->show();
- window->requestActivate();
- QVERIFY(QTest::qWaitForWindowActive(window));
+ QVERIFY(QTest::qWaitForWindowExposed(window));
QQuickPopup *popup = window->property("popup").value<QQuickPopup*>();
QVERIFY(popup);
@@ -485,6 +494,9 @@ void tst_QQuickPopup::closePolicy_data()
void tst_QQuickPopup::closePolicy()
{
+ if (!hasWindowActivation())
+ QSKIP("Window activation is not supported");
+
QFETCH(QString, source);
QFETCH(QQuickPopup::ClosePolicy, closePolicy);
@@ -510,12 +522,15 @@ void tst_QQuickPopup::closePolicy()
QVERIFY(popup->isVisible());
QTRY_VERIFY(popup->isOpened());
+ // wait for dimmer
+ QTest::qWait(50);
+
// press outside popup and its parent
- QTest::mousePress(window, Qt::LeftButton, Qt::NoModifier, QPoint(1, 1), 50);
+ QTest::mousePress(window, Qt::LeftButton, Qt::NoModifier, QPoint(1, 1));
if (closePolicy.testFlag(QQuickPopup::CloseOnPressOutside) || closePolicy.testFlag(QQuickPopup::CloseOnPressOutsideParent))
QTRY_VERIFY(!popup->isVisible());
else
- QVERIFY(popup->isVisible());
+ QVERIFY(popup->isOpened());
popup->open();
QVERIFY(popup->isVisible());
@@ -523,10 +538,10 @@ void tst_QQuickPopup::closePolicy()
// release outside popup and its parent
QTest::mouseRelease(window, Qt::LeftButton, Qt::NoModifier, QPoint(1, 1));
- if (closePolicy.testFlag(QQuickPopup::CloseOnReleaseOutside))
+ if (closePolicy.testFlag(QQuickPopup::CloseOnReleaseOutside) || closePolicy.testFlag(QQuickPopup::CloseOnReleaseOutsideParent))
QTRY_VERIFY(!popup->isVisible());
else
- QVERIFY(popup->isVisible());
+ QVERIFY(popup->isOpened());
popup->open();
QVERIFY(popup->isVisible());
@@ -537,7 +552,7 @@ void tst_QQuickPopup::closePolicy()
if (closePolicy.testFlag(QQuickPopup::CloseOnPressOutside) && !closePolicy.testFlag(QQuickPopup::CloseOnPressOutsideParent))
QTRY_VERIFY(!popup->isVisible());
else
- QVERIFY(popup->isVisible());
+ QVERIFY(popup->isOpened());
popup->open();
QVERIFY(popup->isVisible());
@@ -548,7 +563,7 @@ void tst_QQuickPopup::closePolicy()
if (closePolicy.testFlag(QQuickPopup::CloseOnReleaseOutside) && !closePolicy.testFlag(QQuickPopup::CloseOnReleaseOutsideParent))
QTRY_VERIFY(!popup->isVisible());
else
- QVERIFY(popup->isVisible());
+ QVERIFY(popup->isOpened());
popup->open();
QVERIFY(popup->isVisible());
@@ -557,9 +572,9 @@ void tst_QQuickPopup::closePolicy()
// press inside and release outside
QTest::mousePress(window, Qt::LeftButton, Qt::NoModifier, QPoint(button->x() + popup->x() + 1,
button->y() + popup->y() + 1));
- QVERIFY(popup->isVisible());
+ QVERIFY(popup->isOpened());
QTest::mouseRelease(window, Qt::LeftButton, Qt::NoModifier, QPoint(1, 1));
- QVERIFY(popup->isVisible());
+ QVERIFY(popup->isOpened());
// escape
QTest::keyClick(window, Qt::Key_Escape);
@@ -569,8 +584,59 @@ void tst_QQuickPopup::closePolicy()
QVERIFY(popup->isVisible());
}
+void tst_QQuickPopup::closePolicy_grabberInside_data()
+{
+ qRegisterMetaType<QQuickPopup::ClosePolicy>();
+
+ QTest::addColumn<QString>("source");
+ QTest::addColumn<QQuickPopup::ClosePolicy>("closePolicy");
+
+ QTest::newRow("Window:CloseOnReleaseOutside") << "window.qml"<< static_cast<QQuickPopup::ClosePolicy>(QQuickPopup::CloseOnReleaseOutside);
+ QTest::newRow("Window:CloseOnReleaseOutside|Parent") << "window.qml"<< static_cast<QQuickPopup::ClosePolicy>(QQuickPopup::CloseOnReleaseOutside | QQuickPopup::CloseOnReleaseOutsideParent);
+
+ QTest::newRow("ApplicationWindow:CloseOnReleaseOutside") << "applicationwindow.qml"<< static_cast<QQuickPopup::ClosePolicy>(QQuickPopup::CloseOnReleaseOutside);
+ QTest::newRow("ApplicationWindow:CloseOnReleaseOutside|Parent") << "applicationwindow.qml"<< static_cast<QQuickPopup::ClosePolicy>(QQuickPopup::CloseOnReleaseOutside | QQuickPopup::CloseOnReleaseOutsideParent);
+}
+
+void tst_QQuickPopup::closePolicy_grabberInside()
+{
+ QFETCH(QString, source);
+ QFETCH(QQuickPopup::ClosePolicy, closePolicy);
+
+ QQuickControlsApplicationHelper helper(this, source);
+ QVERIFY2(helper.ready, helper.failureMessage());
+
+ QQuickWindow *window = helper.window;
+ window->show();
+ QVERIFY(QTest::qWaitForWindowExposed(window));
+
+ QQuickPopup *popup = window->property("popup3").value<QQuickPopup*>();
+ QVERIFY(popup);
+
+ QQuickSlider *slider = window->property("slider").value<QQuickSlider*>();
+ QVERIFY(slider);
+
+ popup->setModal(true);
+ popup->setClosePolicy(closePolicy);
+
+ popup->open();
+ QVERIFY(popup->isVisible());
+ QTRY_VERIFY(popup->isOpened());
+
+ // press on a mouse grabber inside and release outside
+ QTest::mousePress(window, Qt::LeftButton, Qt::NoModifier,
+ slider->handle()->mapToItem(window->contentItem(),slider->handle()->boundingRect().center()).toPoint());
+
+ QVERIFY(popup->isOpened());
+ QTest::mouseRelease(window, Qt::LeftButton, Qt::NoModifier, QPoint(1, 1));
+ QVERIFY(popup->isOpened());
+}
+
void tst_QQuickPopup::activeFocusOnClose1()
{
+ if (!hasWindowActivation())
+ QSKIP("Window activation is not supported");
+
// Test that a popup that never sets focus: true (e.g. ToolTip) doesn't affect
// the active focus item when it closes.
QQuickControlsApplicationHelper helper(this, QStringLiteral("activeFocusOnClose1.qml"));
@@ -614,6 +680,9 @@ void tst_QQuickPopup::activeFocusOnClose1()
void tst_QQuickPopup::activeFocusOnClose2()
{
+ if (!hasWindowActivation())
+ QSKIP("Window activation is not supported");
+
// Test that a popup that sets focus: true but relinquishes focus (e.g. by
// calling forceActiveFocus() on another item) before it closes doesn't
// affect the active focus item when it closes.
@@ -653,6 +722,9 @@ void tst_QQuickPopup::activeFocusOnClose2()
void tst_QQuickPopup::activeFocusOnClose3()
{
+ if (!hasWindowActivation())
+ QSKIP("Window activation is not supported");
+
// Test that a closing popup that had focus doesn't steal focus from
// another popup that the focus was transferred to.
QQuickControlsApplicationHelper helper(this, QStringLiteral("activeFocusOnClose3.qml"));
@@ -686,6 +758,9 @@ void tst_QQuickPopup::activeFocusOnClose3()
void tst_QQuickPopup::activeFocusOnClosingSeveralPopups()
{
+ if (!hasWindowActivation())
+ QSKIP("Window activation is not supported");
+
// Test that active focus isn't lost when multiple popup closing simultaneously
QQuickControlsApplicationHelper helper(this, QStringLiteral("activeFocusOnClosingSeveralPopups.qml"));
QVERIFY2(helper.ready, helper.failureMessage());
@@ -735,6 +810,9 @@ void tst_QQuickPopup::activeFocusOnClosingSeveralPopups()
void tst_QQuickPopup::activeFocusAfterExit()
{
+ if (!hasWindowActivation())
+ QSKIP("Window activation is not supported");
+
// Test that after closing a popup the highest one in z-order receives it instead.
QQuickControlsApplicationHelper helper(this, QStringLiteral("activeFocusAfterExit.qml"));
QVERIFY2(helper.ready, helper.failureMessage());
@@ -784,6 +862,9 @@ void tst_QQuickPopup::activeFocusAfterExit()
void tst_QQuickPopup::activeFocusOnDelayedEnter()
{
+ if (!hasWindowActivation())
+ QSKIP("Window activation is not supported");
+
// Test that after opening two popups, first of which has an animation, does not cause
// the first one to receive focus after the animation stops.
QQuickControlsApplicationHelper helper(this, QStringLiteral("activeFocusOnDelayedEnter.qml"));
@@ -826,8 +907,7 @@ void tst_QQuickPopup::hover()
QVERIFY2(helper.ready, helper.failureMessage());
QQuickWindow *window = helper.window;
window->show();
- window->requestActivate();
- QVERIFY(QTest::qWaitForWindowActive(window));
+ QVERIFY(QTest::qWaitForWindowExposed(window));
QQuickPopup *popup = window->property("popup").value<QQuickPopup*>();
QVERIFY(popup);
@@ -1062,7 +1142,7 @@ void tst_QQuickPopup::grabber()
QCOMPARE(combo->isVisible(), false);
// click a menu item to open the popup
- QTest::mouseClick(window, Qt::LeftButton, Qt::NoModifier, QPoint(menu->width() / 2, menu->height() / 2));
+ QTest::mouseClick(window, Qt::LeftButton, Qt::NoModifier, QPoint(menu->x() + menu->width() / 2, menu->y() + menu->height() / 2));
QTRY_COMPARE(menu->isVisible(), false);
QTRY_COMPARE(popup->isOpened(), true);
QCOMPARE(combo->isVisible(), false);
@@ -1152,13 +1232,16 @@ void tst_QQuickPopup::componentComplete()
void tst_QQuickPopup::closeOnEscapeWithNestedPopups()
{
+ if (!hasWindowActivation())
+ QSKIP("Window activation is not supported");
+
// 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.
QQuickControlsApplicationHelper helper(this, QStringLiteral("closeOnEscapeWithNestedPopups.qml"));
QVERIFY2(helper.ready, helper.failureMessage());
QQuickApplicationWindow *window = helper.appWindow;
window->show();
- QVERIFY(QTest::qWaitForWindowExposed(window));
+ QVERIFY(QTest::qWaitForWindowActive(window));
// The stack view should have two items, and it should pop the second when escape is pressed
// and it has focus.
@@ -1188,6 +1271,7 @@ void tst_QQuickPopup::closeOnEscapeWithNestedPopups()
QQuickPopup *settingsDialog = window->contentItem()->findChild<QQuickPopup*>("settingsDialog");
QVERIFY(settingsDialog);
+ QTRY_VERIFY(!optionsMenu->isVisible());
QTRY_VERIFY(settingsDialog->isOpened());
QQuickComboBox *comboBox = window->contentItem()->findChild<QQuickComboBox*>("comboBox");
@@ -1218,6 +1302,9 @@ void tst_QQuickPopup::closeOnEscapeWithNestedPopups()
void tst_QQuickPopup::closeOnEscapeWithVisiblePopup()
{
+ if (!hasWindowActivation())
+ QSKIP("Window activation is not supported");
+
QQuickControlsApplicationHelper helper(this, QStringLiteral("closeOnEscapeWithVisiblePopup.qml"));
QVERIFY2(helper.ready, helper.failureMessage());
QQuickWindow *window = helper.window;
@@ -1309,7 +1396,7 @@ void tst_QQuickPopup::orientation()
QQuickWindow *window = helper.window;
window->reportContentOrientationChange(orientation);
window->show();
- QVERIFY(QTest::qWaitForWindowActive(window));
+ QVERIFY(QTest::qWaitForWindowExposed(window));
QQuickPopup *popup = window->property("popup").value<QQuickPopup*>();
QVERIFY(popup);
@@ -1343,6 +1430,9 @@ void tst_QQuickPopup::qquickview()
// QTBUG-73447
void tst_QQuickPopup::disabledPalette()
{
+ if (!hasWindowActivation())
+ QSKIP("Window activation is not supported");
+
QQuickControlsApplicationHelper helper(this, "disabledPalette.qml");
QVERIFY2(helper.ready, helper.failureMessage());
@@ -1380,6 +1470,9 @@ void tst_QQuickPopup::disabledPalette()
void tst_QQuickPopup::disabledParentPalette()
{
+ if (!hasWindowActivation())
+ QSKIP("Window activation is not supported");
+
QQuickControlsApplicationHelper helper(this, "disabledPalette.qml");
QVERIFY2(helper.ready, helper.failureMessage());
@@ -1431,7 +1524,7 @@ void tst_QQuickPopup::countChanged()
QQuickWindow *window = helper.window;
window->show();
- QVERIFY(QTest::qWaitForWindowActive(window));
+ QVERIFY(QTest::qWaitForWindowExposed(window));
QQuickComboBox *comboBox = window->property("comboBox").value<QQuickComboBox*>();
QVERIFY(comboBox);
@@ -1452,7 +1545,7 @@ void tst_QQuickPopup::toolTipCrashOnClose()
QQuickWindow *window = helper.window;
window->show();
- QVERIFY(QTest::qWaitForWindowActive(window));
+ QVERIFY(QTest::qWaitForWindowExposed(window));
QTest::mouseMove(window, QPoint(window->width() / 2, window->height() / 2));
QTRY_VERIFY(window->property("toolTipOpened").toBool());
@@ -1473,7 +1566,7 @@ void tst_QQuickPopup::setOverlayParentToNull()
centerOnScreen(window);
moveMouseAway(window);
window->show();
- QVERIFY(QTest::qWaitForWindowActive(window));
+ QVERIFY(QTest::qWaitForWindowExposed(window));
QVERIFY(QMetaObject::invokeMethod(window, "nullifyOverlayParent"));
@@ -1486,6 +1579,9 @@ void tst_QQuickPopup::setOverlayParentToNull()
void tst_QQuickPopup::tabFence()
{
+ if (!hasWindowActivation())
+ QSKIP("Window activation is not supported");
+
if (QGuiApplication::styleHints()->tabFocusBehavior() != Qt::TabFocusAllControls)
QSKIP("This platform only allows tab focus for text controls");
@@ -1551,7 +1647,7 @@ void tst_QQuickPopup::invisibleToolTipOpen()
centerOnScreen(window);
moveMouseAway(window);
window->show();
- QVERIFY(QTest::qWaitForWindowActive(window));
+ QVERIFY(QTest::qWaitForWindowExposed(window));
QQuickItem *mouseArea = qvariant_cast<QQuickItem *>(window->property("mouseArea"));
QVERIFY(mouseArea);
@@ -1596,6 +1692,9 @@ void tst_QQuickPopup::centerInOverlayWithinStackViewItem()
void tst_QQuickPopup::destroyDuringExitTransition()
{
+ if (!hasWindowActivation())
+ QSKIP("Window activation is not supported");
+
QQuickControlsApplicationHelper helper(this, "destroyDuringExitTransition.qml");
QVERIFY2(helper.ready, helper.failureMessage());
@@ -1633,7 +1732,7 @@ void tst_QQuickPopup::releaseAfterExitTransition()
QQuickWindow *window = helper.window;
window->show();
- QVERIFY(QTest::qWaitForWindowActive(window));
+ QVERIFY(QTest::qWaitForWindowExposed(window));
QQuickOverlay *overlay = QQuickOverlay::overlay(window);
QQuickPopup *modalPopup = window->property("modalPopup").value<QQuickPopup *>();
@@ -1683,7 +1782,7 @@ void tst_QQuickPopup::dimmerContainmentMask()
QQuickWindow *window = helper.window;
window->show();
QCOMPARE(window->property("clickCount").toInt(), expectedClickCount);
- QVERIFY(QTest::qWaitForWindowActive(window));
+ QVERIFY(QTest::qWaitForWindowExposed(window));
QQuickOverlay *overlay = QQuickOverlay::overlay(window);
QQuickPopup *modalPopup = window->property("modalPopup").value<QQuickPopup *>();