From 349fda471e0df473f38f59c2baae688959d6d273 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Mon, 9 Jan 2023 13:40:16 +0100 Subject: Fix QErrorMessage test when using native dialogs When the test is showing the error message over and over, it's not waiting for the native dialog to actually become visible, and as a result, hiding it has no effect and won't result in a call to processResponse, where we got rid of the native dialog. To fix this we explicitly release the native dialog when encountering this corner case. Add logic to QErrorMessage to test both native and non native dialogs. Pick-to: 6.5 Change-Id: I19ac3f463997aed1e66f646fdfcbb4d2459116d1 Reviewed-by: Volker Hilsheimer --- .../widgets/dialogs/qerrormessage/CMakeLists.txt | 1 + .../dialogs/qerrormessage/tst_qerrormessage.cpp | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) (limited to 'tests/auto/widgets/dialogs') diff --git a/tests/auto/widgets/dialogs/qerrormessage/CMakeLists.txt b/tests/auto/widgets/dialogs/qerrormessage/CMakeLists.txt index ba4ea75b79..1cb63beea9 100644 --- a/tests/auto/widgets/dialogs/qerrormessage/CMakeLists.txt +++ b/tests/auto/widgets/dialogs/qerrormessage/CMakeLists.txt @@ -12,6 +12,7 @@ qt_internal_add_test(tst_qerrormessage tst_qerrormessage.cpp LIBRARIES Qt::Gui + Qt::GuiPrivate Qt::Widgets ) diff --git a/tests/auto/widgets/dialogs/qerrormessage/tst_qerrormessage.cpp b/tests/auto/widgets/dialogs/qerrormessage/tst_qerrormessage.cpp index 97dad396e5..5cae8263dc 100644 --- a/tests/auto/widgets/dialogs/qerrormessage/tst_qerrormessage.cpp +++ b/tests/auto/widgets/dialogs/qerrormessage/tst_qerrormessage.cpp @@ -5,16 +5,38 @@ #include #include +#include +#include + class tst_QErrorMessage : public QObject { Q_OBJECT private slots: + void initTestCase_data(); + void init(); + void dontShowAgain(); void dontShowCategoryAgain(); }; +void tst_QErrorMessage::initTestCase_data() +{ + QTest::addColumn("useNativeDialog"); + QTest::newRow("widget") << false; + if (const QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme()) { + if (theme->usePlatformNativeDialog(QPlatformTheme::MessageDialog)) + QTest::newRow("native") << true; + } +} + +void tst_QErrorMessage::init() +{ + QFETCH_GLOBAL(bool, useNativeDialog); + qApp->setAttribute(Qt::AA_DontUseNativeDialogs, !useNativeDialog); +} + void tst_QErrorMessage::dontShowAgain() { QString plainString = QLatin1String("foo"); -- cgit v1.2.3