tst_QDialogButtonBox::hideAndShowButton: Wait for focus widget

Spin the event loop with QTRY_VERIFY when checking the dialog box's
focus widget, to stop flaking.

Pick-to: 6.6 6.5
Change-Id: I24fab1264796e05645da4c12e4672daec9b06067
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
This commit is contained in:
Axel Spoerl 2023-07-07 17:21:34 +02:00
parent 04f2acf93a
commit 25f7d95fce

View File

@ -7,6 +7,7 @@
#include <QtWidgets/QLayout>
#include <QtWidgets/QDialog>
#include <QtGui/QAction>
#include <QtGui/QStyleHints>
#include <qdialogbuttonbox.h>
#include <QtWidgets/private/qdialogbuttonbox_p.h>
#include <QtWidgets/private/qabstractbutton_p.h>
@ -380,6 +381,9 @@ void tst_QDialogButtonBox::removeButton()
#ifdef QT_BUILD_INTERNAL
void tst_QDialogButtonBox::hideAndShowButton()
{
if (QGuiApplication::styleHints()->tabFocusBehavior() == Qt::NoTabFocus)
QSKIP("Test skipped with Qt::NoTabFocus");
QDialogButtonBox buttonBox;
QDialogButtonBoxPrivate *d = static_cast<QDialogButtonBoxPrivate *>(QObjectPrivate::get(&buttonBox));
auto *apply = buttonBox.addButton( "Apply", QDialogButtonBox::ApplyRole );
@ -402,7 +406,7 @@ void tst_QDialogButtonBox::hideAndShowButton()
hideButton->hide();
widget->show();
QVERIFY(QTest::qWaitForWindowExposed(widget));
QVERIFY(buttonBox.focusWidget()); // QTBUG-114377: Without fixing, focusWidget() == nullptr
QTRY_VERIFY(buttonBox.focusWidget()); // QTBUG-114377: Without fixing, focusWidget() == nullptr
QCOMPARE(d->visibleButtons().count(), 2);
QCOMPARE(d->hiddenButtons.count(), 1);
QVERIFY(d->hiddenButtons.contains(hideButton));