diff options
Diffstat (limited to 'tests/auto/quickcontrols2/qquickpopup/tst_qquickpopup.cpp')
-rw-r--r-- | tests/auto/quickcontrols2/qquickpopup/tst_qquickpopup.cpp | 151 |
1 files changed, 151 insertions, 0 deletions
diff --git a/tests/auto/quickcontrols2/qquickpopup/tst_qquickpopup.cpp b/tests/auto/quickcontrols2/qquickpopup/tst_qquickpopup.cpp index 75d66335f1..d2cfda9375 100644 --- a/tests/auto/quickcontrols2/qquickpopup/tst_qquickpopup.cpp +++ b/tests/auto/quickcontrols2/qquickpopup/tst_qquickpopup.cpp @@ -118,6 +118,8 @@ private slots: void dimmerContainmentMask(); void shrinkPopupThatWasLargerThanWindow_data(); void shrinkPopupThatWasLargerThanWindow(); + void mirroredCombobox(); + void rotatedCombobox(); private: static bool hasWindowActivation(); @@ -1878,6 +1880,155 @@ void tst_QQuickPopup::shrinkPopupThatWasLargerThanWindow() .arg(popup->height()).arg(window->height()))); } +void tst_QQuickPopup::mirroredCombobox() +{ +#ifdef Q_OS_ANDROID + // Android screens might be pretty small, such that additional + // repositioning (apart from the mirroring) will happen to the + // popups and mess up the expected positions below. + QSKIP("Skipping test for Android."); +#endif + QStringList nativeStyles; + nativeStyles.append("macOS"); + nativeStyles.append("iOS"); + nativeStyles.append("Windows"); + if (nativeStyles.contains(QQuickStyle::name())) + QSKIP("Skipping test for native styles: they might rearrange their combobox the way they " + "want."); + + QQuickControlsApplicationHelper helper(this, "mirroredCombobox.qml"); + QVERIFY2(helper.ready, helper.failureMessage()); + + QQuickWindow *window = helper.window; + window->show(); + QVERIFY(QTest::qWaitForWindowExposed(window)); + + { + QQuickComboBox *comboBox = window->findChild<QQuickComboBox *>("first"); + QVERIFY(comboBox); + QQuickPopup *popup = comboBox->popup(); + QVERIFY(popup); + popup->open(); + QTRY_COMPARE(popup->isVisible(), true); + const QPointF popupPos(popup->contentItem()->mapToItem(comboBox->parentItem(), + popup->contentItem()->position())); + const QSizeF popupSize(popup->contentItem()->size()); + + // ignore popup.{top,bottom}Padding() as not included in popup->contentItem()->size() + // some styles prefer to draw the popup "over" (in z-axis direction) the combobox to hide + // the combobox + const bool styleDrawsPopupOverCombobox = + comboBox->position().y() - popupSize.height() + comboBox->size().height() + == popupPos.y(); + // some styles prefer to draw the popup below (in y-axis direction) the combobox + const bool styleDrawsPopupBelowCombobox = + comboBox->position().y() - popupSize.height() + comboBox->topPadding() + == popupPos.y(); + + QVERIFY(styleDrawsPopupOverCombobox || styleDrawsPopupBelowCombobox); + + popup->close(); + } + + { + QQuickComboBox *comboBox = window->findChild<QQuickComboBox *>("second"); + QVERIFY(comboBox); + QQuickPopup *popup = comboBox->popup(); + QVERIFY(popup); + popup->open(); + QTRY_COMPARE(popup->isVisible(), true); + const QPointF popupPos(popup->contentItem()->mapToItem(comboBox->parentItem(), + popup->contentItem()->position())); + + // some styles prefer to draw the popup "over" (in z-axis direction) the combobox to hide + // the combobox + const bool styleDrawsPopupOverCombobox = comboBox->position().y() + comboBox->topPadding() + + popup->topPadding() + popup->bottomPadding() + == popupPos.y(); + // some styles prefer to draw the popup above (in y-axis direction) the combobox + const bool styleDrawsPopupAboveCombobox = + comboBox->position().y() + comboBox->height() - comboBox->topPadding() + == popupPos.y(); + + QVERIFY(styleDrawsPopupOverCombobox || styleDrawsPopupAboveCombobox); + + popup->close(); + } +} + +void tst_QQuickPopup::rotatedCombobox() +{ +#ifdef Q_OS_ANDROID + // Android screens might be pretty small, such that additional + // repositioning (apart from the rotating) will happen to the + // popups and mess up the expected positions below. + QSKIP("Skipping test for Android."); +#endif + QStringList nativeStyles; + nativeStyles.append("macOS"); + nativeStyles.append("iOS"); + nativeStyles.append("Windows"); + if (nativeStyles.contains(QQuickStyle::name())) + QSKIP("Skipping test for native styles: they might rearrange their combobox the way they " + "want."); + + QQuickControlsApplicationHelper helper(this, "rotatedCombobox.qml"); + QVERIFY2(helper.ready, helper.failureMessage()); + + QQuickWindow *window = helper.window; + window->show(); + QVERIFY(QTest::qWaitForWindowExposed(window)); + + { + QQuickComboBox *comboBox = window->findChild<QQuickComboBox *>("first"); + QVERIFY(comboBox); + QQuickPopup *popup = comboBox->popup(); + QVERIFY(popup); + popup->open(); + QTRY_COMPARE(popup->isVisible(), true); + const QPointF popupPos(popup->contentItem()->mapToItem(comboBox->parentItem(), + popup->contentItem()->position())); + const QSizeF popupSize(popup->contentItem()->size()); + + // ignore popup.{left,right}Padding() as not included in popup->contentItem()->size() + // some styles prefer to draw the popup "over" (in z-axis direction) the combobox to hide + // the combobox + const bool styleDrawsPopupOverCombobox = + comboBox->position().x() - popupSize.width() + comboBox->width() == popupPos.x(); + // some styles prefer to draw the popup right (in x-axis direction) of the combobox + const bool styleDrawsPopupBelowCombobox = + comboBox->position().x() - popupSize.width() - comboBox->leftPadding() + == popupPos.x(); + + QVERIFY(styleDrawsPopupOverCombobox || styleDrawsPopupBelowCombobox); + } + + { + QQuickComboBox *comboBox = window->findChild<QQuickComboBox *>("second"); + QVERIFY(comboBox); + QQuickPopup *popup = comboBox->popup(); + QVERIFY(popup); + popup->open(); + QTRY_COMPARE(popup->isVisible(), true); + const QPointF popupPos(popup->contentItem()->mapToItem(comboBox->parentItem(), + popup->contentItem()->position())); + + // some styles prefer to draw the popup "over" (in z-axis direction) the combobox to hide + // the combobox + const bool styleDrawsPopupOverCombobox = comboBox->position().x() + comboBox->leftPadding() + + popup->leftPadding() + popup->rightPadding() + == popupPos.x(); + // some styles prefer to draw the popup left (in y-axis direction) of the combobox + const bool styleDrawsPopupAboveCombobox = + comboBox->position().x() + comboBox->width() - comboBox->leftPadding() + == popupPos.x(); + + QVERIFY(styleDrawsPopupOverCombobox || styleDrawsPopupAboveCombobox); + + popup->close(); + } +} + QTEST_QUICKCONTROLS_MAIN(tst_QQuickPopup) #include "tst_qquickpopup.moc" |