Refactor and modify auto test tst_QWidget::palettePropagation2()
Refactor auto test tst_QWidget::palettePropagation2() to use QWidgetList instead of rewriting the same code several times. Add a lambda that ensure widgets are polished before comparing them. Fix flakiness on Ubuntu 22.04 Change-Id: I6e6b26cf153c441b7d69cfe1a0b2fd604a08cde8 Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
This commit is contained in:
parent
0afe31fa51
commit
0fce5caf95
@ -1098,6 +1098,15 @@ void tst_QWidget::palettePropagation()
|
|||||||
QCOMPARE( newPalette, grandChildWidget->palette() );
|
QCOMPARE( newPalette, grandChildWidget->palette() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool waitForPolished(QWidgetList widgets)
|
||||||
|
{
|
||||||
|
for (const auto *widget : widgets) {
|
||||||
|
if (!QTest::qWaitFor([widget]{ return widget->testAttribute(Qt::WA_WState_Polished); }))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void tst_QWidget::palettePropagation2()
|
void tst_QWidget::palettePropagation2()
|
||||||
{
|
{
|
||||||
if (QGuiApplication::platformName().startsWith(QLatin1String("wayland"), Qt::CaseInsensitive))
|
if (QGuiApplication::platformName().startsWith(QLatin1String("wayland"), Qt::CaseInsensitive))
|
||||||
@ -1109,73 +1118,67 @@ void tst_QWidget::palettePropagation2()
|
|||||||
// palette.setColor(QPalette::Text, QColor(21, 22, 23));
|
// palette.setColor(QPalette::Text, QColor(21, 22, 23));
|
||||||
// qApp->setPalette(palette, "QPropagationTestWidget");
|
// qApp->setPalette(palette, "QPropagationTestWidget");
|
||||||
|
|
||||||
QScopedPointer<QWidget> root(new QWidget);
|
QWidget root;
|
||||||
root->setObjectName(QLatin1String("palettePropagation2"));
|
root.setObjectName(QTest::currentTestFunction());
|
||||||
root->setWindowTitle(root->objectName());
|
root.setWindowTitle(root.objectName());
|
||||||
root->resize(200, 200);
|
root.resize(200, 200);
|
||||||
QWidget *child0 = new QWidget(root.data());
|
|
||||||
QWidget *child1 = new QWidget(child0);
|
QWidget *parent = &root;
|
||||||
QWidget *child2 = new QPropagationTestWidget(child1);
|
static constexpr int propagationIndex = 2;
|
||||||
QWidget *child3 = new QWidget(child2);
|
QWidgetList children;
|
||||||
QWidget *child4 = new QWidget(child3);
|
for (int i = 0; i < 6; ++i) {
|
||||||
QWidget *child5 = new QWidget(child4);
|
QWidget *w = (propagationIndex == i) ? new QPropagationTestWidget(parent) : new QWidget(parent);
|
||||||
root->show();
|
w->setObjectName(QString("Widget-%1").arg(i));
|
||||||
QVERIFY(QTest::qWaitForWindowExposed(root.data()));
|
children << w;
|
||||||
|
parent = w;
|
||||||
|
}
|
||||||
|
|
||||||
|
root.show();
|
||||||
|
QVERIFY(QTest::qWaitForWindowExposed(&root));
|
||||||
|
|
||||||
// These colors are unlikely to be imposed on the default palette of
|
// These colors are unlikely to be imposed on the default palette of
|
||||||
// QWidget ;-).
|
// QWidget ;-).
|
||||||
QColor sysPalText(21, 22, 23);
|
static constexpr QColor sysPalText(21, 22, 23);
|
||||||
QColor sysPalToolTipBase(12, 13, 14);
|
static constexpr QColor sysPalToolTipBase(12, 13, 14);
|
||||||
QColor overridePalText(42, 43, 44);
|
static constexpr QColor overridePalText(42, 43, 44);
|
||||||
QColor overridePalToolTipBase(45, 46, 47);
|
static constexpr QColor overridePalToolTipBase(45, 46, 47);
|
||||||
QColor sysPalButton(99, 98, 97);
|
static constexpr QColor sysPalButton(99, 98, 97);
|
||||||
|
|
||||||
// Check that only the application fonts apply.
|
// Check that only the application fonts apply.
|
||||||
QPalette appPal = QApplication::palette();
|
const QPalette &appPal = QApplication::palette();
|
||||||
QCOMPARE(root->palette(), appPal);
|
waitForPolished(children);
|
||||||
QCOMPARE(child0->palette(), appPal);
|
QCOMPARE(root.palette(), appPal);
|
||||||
QCOMPARE(child1->palette(), appPal);
|
QCOMPARE(children.at(0)->palette(), appPal);
|
||||||
QCOMPARE(child2->palette().color(QPalette::ToolTipBase), sysPalToolTipBase);
|
QCOMPARE(children.at(1)->palette(), appPal);
|
||||||
QCOMPARE(child2->palette().color(QPalette::Text), sysPalText);
|
|
||||||
QCOMPARE(child2->palette().color(QPalette::ToolTipText), appPal.color(QPalette::ToolTipText));
|
|
||||||
QCOMPARE(child3->palette().color(QPalette::ToolTipBase), sysPalToolTipBase);
|
|
||||||
QCOMPARE(child3->palette().color(QPalette::Text), sysPalText);
|
|
||||||
QCOMPARE(child3->palette().color(QPalette::ToolTipText), appPal.color(QPalette::ToolTipText));
|
|
||||||
QCOMPARE(child4->palette().color(QPalette::ToolTipBase), sysPalToolTipBase);
|
|
||||||
QCOMPARE(child4->palette().color(QPalette::Text), sysPalText);
|
|
||||||
QCOMPARE(child4->palette().color(QPalette::ToolTipText), appPal.color(QPalette::ToolTipText));
|
|
||||||
QCOMPARE(child5->palette().color(QPalette::ToolTipBase), sysPalToolTipBase);
|
|
||||||
QCOMPARE(child5->palette().color(QPalette::Text), sysPalText);
|
|
||||||
QCOMPARE(child5->palette().color(QPalette::ToolTipText), appPal.color(QPalette::ToolTipText));
|
|
||||||
|
|
||||||
// Set child0's Text, and set ToolTipBase on child4.
|
for (int i = 2; i < children.count(); i++) {
|
||||||
|
QCOMPARE(children.at(i)->palette().color(QPalette::ToolTipBase), sysPalToolTipBase);
|
||||||
|
QCOMPARE(children.at(i)->palette().color(QPalette::Text), sysPalText);
|
||||||
|
QCOMPARE(children.at(i)->palette().color(QPalette::ToolTipText), appPal.color(QPalette::ToolTipText));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set children.at(0)'s Text, and set ToolTipBase on children.at(4).
|
||||||
QPalette textPalette;
|
QPalette textPalette;
|
||||||
textPalette.setColor(QPalette::Text, overridePalText);
|
textPalette.setColor(QPalette::Text, overridePalText);
|
||||||
child0->setPalette(textPalette);
|
children.at(0)->setPalette(textPalette);
|
||||||
QPalette toolTipPalette;
|
QPalette toolTipPalette;
|
||||||
toolTipPalette.setColor(QPalette::ToolTipBase, overridePalToolTipBase);
|
toolTipPalette.setColor(QPalette::ToolTipBase, overridePalToolTipBase);
|
||||||
child4->setPalette(toolTipPalette);
|
children.at(4)->setPalette(toolTipPalette);
|
||||||
|
|
||||||
// Check that the above settings propagate correctly.
|
// Check that the above settings propagate correctly.
|
||||||
QCOMPARE(root->palette(), appPal);
|
waitForPolished(children);
|
||||||
QCOMPARE(child0->palette().color(QPalette::Text), overridePalText);
|
QCOMPARE(root.palette(), appPal);
|
||||||
QCOMPARE(child0->palette().color(QPalette::ToolTipBase), appPal.color(QPalette::ToolTipBase));
|
|
||||||
QCOMPARE(child0->palette().color(QPalette::ToolTipText), appPal.color(QPalette::ToolTipText));
|
for (int i = 0; i < children.count(); i++) {
|
||||||
QCOMPARE(child1->palette().color(QPalette::Text), overridePalText);
|
QCOMPARE(children.at(i)->palette().color(QPalette::Text), overridePalText);
|
||||||
QCOMPARE(child1->palette().color(QPalette::ToolTipBase), appPal.color(QPalette::ToolTipBase));
|
QCOMPARE(children.at(i)->palette().color(QPalette::ToolTipText), appPal.color(QPalette::ToolTipText));
|
||||||
QCOMPARE(child1->palette().color(QPalette::ToolTipText), appPal.color(QPalette::ToolTipText));
|
if (i <= 1)
|
||||||
QCOMPARE(child2->palette().color(QPalette::Text), overridePalText);
|
QCOMPARE(children.at(i)->palette().color(QPalette::ToolTipBase), appPal.color(QPalette::ToolTipBase));
|
||||||
QCOMPARE(child2->palette().color(QPalette::ToolTipBase), sysPalToolTipBase);
|
else if (i <= 3)
|
||||||
QCOMPARE(child2->palette().color(QPalette::ToolTipText), appPal.color(QPalette::ToolTipText));
|
QCOMPARE(children.at(i)->palette().color(QPalette::ToolTipBase), sysPalToolTipBase);
|
||||||
QCOMPARE(child3->palette().color(QPalette::Text), overridePalText);
|
else if (i <= 5)
|
||||||
QCOMPARE(child3->palette().color(QPalette::ToolTipBase), sysPalToolTipBase);
|
QCOMPARE(children.at(i)->palette().color(QPalette::ToolTipBase), overridePalToolTipBase);
|
||||||
QCOMPARE(child3->palette().color(QPalette::ToolTipText), appPal.color(QPalette::ToolTipText));
|
}
|
||||||
QCOMPARE(child4->palette().color(QPalette::Text), overridePalText);
|
|
||||||
QCOMPARE(child4->palette().color(QPalette::ToolTipBase), overridePalToolTipBase);
|
|
||||||
QCOMPARE(child4->palette().color(QPalette::ToolTipText), appPal.color(QPalette::ToolTipText));
|
|
||||||
QCOMPARE(child5->palette().color(QPalette::Text), overridePalText);
|
|
||||||
QCOMPARE(child5->palette().color(QPalette::ToolTipBase), overridePalToolTipBase);
|
|
||||||
QCOMPARE(child5->palette().color(QPalette::ToolTipText), appPal.color(QPalette::ToolTipText));
|
|
||||||
|
|
||||||
// Replace the app palette for child2. Button should propagate but Text
|
// Replace the app palette for child2. Button should propagate but Text
|
||||||
// should still be ignored. The previous ToolTipBase setting is gone.
|
// should still be ignored. The previous ToolTipBase setting is gone.
|
||||||
@ -1184,25 +1187,20 @@ void tst_QWidget::palettePropagation2()
|
|||||||
QApplication::setPalette(buttonPalette, "QPropagationTestWidget");
|
QApplication::setPalette(buttonPalette, "QPropagationTestWidget");
|
||||||
|
|
||||||
// Check that the above settings propagate correctly.
|
// Check that the above settings propagate correctly.
|
||||||
QCOMPARE(root->palette(), appPal);
|
waitForPolished(children);
|
||||||
QCOMPARE(child0->palette().color(QPalette::Text), overridePalText);
|
QCOMPARE(root.palette(), appPal);
|
||||||
QCOMPARE(child0->palette().color(QPalette::ToolTipBase), appPal.color(QPalette::ToolTipBase));
|
|
||||||
QCOMPARE(child0->palette().color(QPalette::ToolTipText), appPal.color(QPalette::ToolTipText));
|
for (int i = 0; i < children.count(); i++) {
|
||||||
QCOMPARE(child1->palette().color(QPalette::Text), overridePalText);
|
QCOMPARE(children.at(i)->palette().color(QPalette::Text), overridePalText);
|
||||||
QCOMPARE(child1->palette().color(QPalette::ToolTipBase), appPal.color(QPalette::ToolTipBase));
|
if (i <= 1)
|
||||||
QCOMPARE(child1->palette().color(QPalette::ToolTipText), appPal.color(QPalette::ToolTipText));
|
QCOMPARE(children.at(i)->palette().color(QPalette::ToolTipText), appPal.color(QPalette::ToolTipText));
|
||||||
QCOMPARE(child2->palette().color(QPalette::Text), overridePalText);
|
if (i <= 3)
|
||||||
QCOMPARE(child2->palette().color(QPalette::ToolTipBase), appPal.color(QPalette::ToolTipBase));
|
QCOMPARE(children.at(i)->palette().color(QPalette::ToolTipBase), appPal.color(QPalette::ToolTipBase));
|
||||||
QCOMPARE(child2->palette().color(QPalette::ToolTipText), sysPalButton);
|
else if (i < children.count()) {
|
||||||
QCOMPARE(child3->palette().color(QPalette::Text), overridePalText);
|
QCOMPARE(children.at(i)->palette().color(QPalette::ToolTipBase), overridePalToolTipBase);
|
||||||
QCOMPARE(child3->palette().color(QPalette::ToolTipBase), appPal.color(QPalette::ToolTipBase));
|
QCOMPARE(children.at(i)->palette().color(QPalette::ToolTipText), sysPalButton);
|
||||||
QCOMPARE(child3->palette().color(QPalette::ToolTipText), sysPalButton);
|
}
|
||||||
QCOMPARE(child4->palette().color(QPalette::Text), overridePalText);
|
}
|
||||||
QCOMPARE(child4->palette().color(QPalette::ToolTipBase), overridePalToolTipBase);
|
|
||||||
QCOMPARE(child4->palette().color(QPalette::ToolTipText), sysPalButton);
|
|
||||||
QCOMPARE(child5->palette().color(QPalette::Text), overridePalText);
|
|
||||||
QCOMPARE(child5->palette().color(QPalette::ToolTipBase), overridePalToolTipBase);
|
|
||||||
QCOMPARE(child5->palette().color(QPalette::ToolTipText), sysPalButton);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
Loading…
x
Reference in New Issue
Block a user