diff options
Diffstat (limited to 'tests/auto/quickcontrols/palette/tst_palette.cpp')
| -rw-r--r-- | tests/auto/quickcontrols/palette/tst_palette.cpp | 125 |
1 files changed, 125 insertions, 0 deletions
diff --git a/tests/auto/quickcontrols/palette/tst_palette.cpp b/tests/auto/quickcontrols/palette/tst_palette.cpp index d8f4bfd804..621475b86e 100644 --- a/tests/auto/quickcontrols/palette/tst_palette.cpp +++ b/tests/auto/quickcontrols/palette/tst_palette.cpp @@ -7,17 +7,21 @@ #include <QtQml/qqmlengine.h> #include <QtQml/qqmlcomponent.h> #include <QtQuickTestUtils/private/qmlutils_p.h> +#include <QtQuickTestUtils/private/visualtestutils_p.h> #include <QtQuickControlsTestUtils/private/controlstestutils_p.h> #include <QtQuick/private/qquickitem_p.h> #include <QtQuickTemplates2/private/qquickapplicationwindow_p.h> +#include <QtQuickTemplates2/private/qquickcombobox_p.h> #include <QtQuickTemplates2/private/qquickcontrol_p.h> #include <QtQuickTemplates2/private/qquickcontrol_p_p.h> #include <QtQuickTemplates2/private/qquickpopup_p.h> #include <QtQuickTemplates2/private/qquickpopup_p_p.h> #include <QtQuickTemplates2/private/qquicktheme_p_p.h> #include <QtQuickTemplates2/private/qquickbutton_p.h> +#include <QtQuickTemplates2/private/qquicktooltip_p.h> #include <QtQuickControls2/qquickstyle.h> +using namespace QQuickVisualTestUtils; using namespace QQuickControlsTestUtils; // Need a more descriptive failure message: QTBUG-87039 @@ -55,6 +59,13 @@ private slots: void resolve(); void updateBindingPalette(); + + void comboBoxPopup_data(); + void comboBoxPopup(); + void comboBoxPopupWithThemeDefault_data(); + void comboBoxPopupWithThemeDefault(); + + void toolTipPaletteUpdate(); }; tst_palette::tst_palette() @@ -485,6 +496,120 @@ void tst_palette::updateBindingPalette() QCOMPARE(windowPalette->buttonText(), customPalette->buttonText()); } +void tst_palette::comboBoxPopup_data() +{ + QTest::addColumn<QString>("style"); + QTest::addColumn<QString>("qmlFilePath"); + + QTest::newRow("Window, Basic") << "Basic" << "comboBoxPopupWithWindow.qml"; + QTest::newRow("ApplicationWindow, Basic") << "Basic" << "comboBoxPopupWithApplicationWindow.qml"; + QTest::newRow("Window, Fusion") << "Fusion" << "comboBoxPopupWithWindow.qml"; + QTest::newRow("ApplicationWindow, Fusion") << "Fusion" << "comboBoxPopupWithApplicationWindow.qml"; +} + +// Unlike regular popups, which should inherit their palette from the window and not the parent popup, +// combo box popups should inherit their palette from the combo box itself. +void tst_palette::comboBoxPopup() +{ + QFETCH(QString, style); + QFETCH(QString, qmlFilePath); + + qmlClearTypeRegistrations(); + QQuickStyle::setStyle(style); + + QQuickApplicationHelper helper(this, qmlFilePath); + QVERIFY2(helper.ready, helper.failureMessage()); + QQuickWindow *window = helper.window; + window->show(); + QVERIFY(QTest::qWaitForWindowExposed(window)); + + const auto *windowPalette = window->property("palette").value<QQuickPalette *>(); + QVERIFY(windowPalette); + + const auto *popup = window->property("popup").value<QQuickPopup *>(); + QVERIFY(popup); + const auto *popupBackground = popup->background(); + QCOMPARE(popupBackground->property("color"), QColorConstants::Red); + QCOMPARE(popupBackground->property("palette").value<QQuickPalette*>()->toQPalette().window().color(), + QColorConstants::Red); + + // This has the default palette. + const auto *topLevelComboBox = window->property("topLevelComboBox").value<QQuickComboBox *>(); + QVERIFY(topLevelComboBox); + const auto *topLevelComboBoxBackground = topLevelComboBox->popup()->background(); + QCOMPARE_NE(topLevelComboBoxBackground->property("color"), QColorConstants::Red); + QCOMPARE_NE(topLevelComboBoxBackground->property("palette").value<QQuickPalette*>()->toQPalette().window().color(), + QColorConstants::Red); + + // The popup that this combo box is in has its window role set to red, + // so the combo box's popup background should be red too. + const auto *comboBoxInPopup = window->property("comboBoxInPopup").value<QQuickComboBox *>(); + QVERIFY(comboBoxInPopup); + const auto *comboBoxInPopupBackground = comboBoxInPopup->popup()->background(); + QCOMPARE(comboBoxInPopupBackground->property("color"), QColorConstants::Red); + QCOMPARE(comboBoxInPopupBackground->property("palette").value<QQuickPalette*>()->toQPalette().window().color(), + QColorConstants::Red); +} + +void tst_palette::comboBoxPopupWithThemeDefault_data() +{ + QTest::addColumn<QString>("style"); + QTest::addColumn<QColor>("expectedComboBoxPopupBackgroundColor"); + + QTest::newRow("Basic") << "Basic" << QColor::fromRgb(0xFFFFFF); + + // We can't test Fusion because it uses the default application palette, + // which is the default-constructed QPalette, so the test would always pass. +} + +void tst_palette::comboBoxPopupWithThemeDefault() +{ + QFETCH(QString, style); + QFETCH(QColor, expectedComboBoxPopupBackgroundColor); + + qmlClearTypeRegistrations(); + QQuickStyle::setStyle(style); + + QQuickApplicationHelper helper(this, "comboBoxPopupWithThemeDefault.qml"); + QVERIFY2(helper.ready, helper.failureMessage()); + QQuickWindow *window = helper.window; + window->show(); + QVERIFY(QTest::qWaitForWindowExposed(window)); + + const auto *comboBox = window->property("comboBox").value<QQuickComboBox *>(); + QVERIFY(comboBox); + const auto *comboBoxBackground = comboBox->popup()->background(); + QCOMPARE(comboBoxBackground->property("color"), expectedComboBoxPopupBackgroundColor); +} + +void tst_palette::toolTipPaletteUpdate() +{ + QQuickApplicationHelper helper(this, "toolTipPaletteUpdate.qml"); + QVERIFY2(helper.ready, helper.failureMessage()); + QQuickWindow *window = helper.window; + window->show(); + QVERIFY(QTest::qWaitForWindowExposed(window)); + + auto *button = window->findChild<QQuickButton *>("button"); + QVERIFY(button); + auto *attachedToolTip = button->findChild<QQuickToolTipAttached *>(); + QVERIFY(attachedToolTip); + auto *toolTip = attachedToolTip->toolTip(); + QVERIFY(toolTip); + + auto windowPalette = QQuickWindowPrivate::get(window)->palette(); + auto toolTipPalette = QQuickPopupPrivate::get(toolTip)->palette(); + + QCOMPARE(toolTipPalette->toolTipBase(), windowPalette->toolTipBase()); + QCOMPARE(toolTipPalette->toolTipText(), windowPalette->toolTipText()); + + windowPalette->setToolTipBase(Qt::blue); + windowPalette->setToolTipText(Qt::red); + + QCOMPARE(toolTipPalette->toolTipBase(), windowPalette->toolTipBase()); + QCOMPARE(toolTipPalette->toolTipText(), windowPalette->toolTipText()); +} + QTEST_MAIN(tst_palette) #include "tst_palette.moc" |
