diff options
author | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2023-10-25 11:29:35 +0200 |
---|---|---|
committer | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2023-10-25 17:41:32 +0200 |
commit | 1af821825a4173532cf14024ea9bebc75bf3c62c (patch) | |
tree | f4ee961c0a4b8ae9a2d13a25d41a7c1686204233 | |
parent | 7fb0c2bbf9af7956e6b8a0b1906792437aa40517 (diff) |
macOS: Fix tst_MacGui::nonModalOrder()
The test is testing whether the order of creating a child window
of a modal dialog and showing the parent dialog matters. But to
allow child windows of a modal dialog to become active that child
also needs to be a dialog. That's a limitation on macOS, where
only NSPanel subclasses can override worksWhenModal.
Fix the test, and rewrite it using more modern idioms, avoiding
the need for long waits in the test.
Pick-to: 6.6 6.5
Change-Id: Ifb640d0288a3c7ed37f2c61294e34cd96fba49ca
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
-rw-r--r-- | tests/auto/other/macgui/BLACKLIST | 3 | ||||
-rw-r--r-- | tests/auto/other/macgui/tst_macgui.cpp | 61 |
2 files changed, 22 insertions, 42 deletions
diff --git a/tests/auto/other/macgui/BLACKLIST b/tests/auto/other/macgui/BLACKLIST index 05e529e519..a6dc56611b 100644 --- a/tests/auto/other/macgui/BLACKLIST +++ b/tests/auto/other/macgui/BLACKLIST @@ -1,5 +1,2 @@ -[nonModalOrder] -osx - [scrollbarPainting] macos diff --git a/tests/auto/other/macgui/tst_macgui.cpp b/tests/auto/other/macgui/tst_macgui.cpp index 4d09db9b7f..712f5e9daa 100644 --- a/tests/auto/other/macgui/tst_macgui.cpp +++ b/tests/auto/other/macgui/tst_macgui.cpp @@ -126,40 +126,6 @@ void tst_MacGui::splashScreenModality() QVERIFY(!QTestEventLoop::instance().timeout()); } -class PrimaryWindowDialog : public QDialog -{ -Q_OBJECT -public: - PrimaryWindowDialog(); - QWidget *secondaryWindow; - QWidget *frontWidget; -public slots: - void showSecondaryWindow(); - void test(); -}; - -PrimaryWindowDialog::PrimaryWindowDialog() : QDialog(0) -{ - frontWidget = 0; - secondaryWindow = new ColorWidget(this); - secondaryWindow->setWindowFlags(Qt::Window); - secondaryWindow->resize(400, 400); - secondaryWindow->move(100, 100); - QTimer::singleShot(1000, this, SLOT(showSecondaryWindow())); - QTimer::singleShot(2000, this, SLOT(test())); - QTimer::singleShot(3000, this, SLOT(close())); -} - -void PrimaryWindowDialog::showSecondaryWindow() -{ - secondaryWindow->show(); -} - -void PrimaryWindowDialog::test() -{ - frontWidget = QApplication::widgetAt(secondaryWindow->mapToGlobal(QPoint(100, 100))); -} - /* Test that a non-modal child window of a modal dialog is shown in front of the dialog even if the dialog becomes modal after the child window @@ -168,11 +134,28 @@ void PrimaryWindowDialog::test() void tst_MacGui::nonModalOrder() { clearSequence(); - PrimaryWindowDialog primary; - primary.resize(400, 400); - primary.move(100, 100); - primary.exec(); - QCOMPARE(primary.frontWidget, primary.secondaryWindow); + + QDialog dialog; + dialog.resize(400, 400); + dialog.move(100, 100); + + ColorWidget child(&dialog); + // The child window needs to be a dialog, as only subclasses of NSPanel + // are allowed to override worksWhenModal, which is needed to mark the + // transient child as working within the modal session of the parent. + child.setWindowFlags(Qt::Window | Qt::Dialog); + child.resize(400, 400); + child.move(100, 100); + + QTimer::singleShot(0, [&]{ + QVERIFY(QTest::qWaitForWindowExposed(&dialog)); + child.show(); + QVERIFY(QTest::qWaitForWindowExposed(&child)); + QCOMPARE(QApplication::widgetAt(child.mapToGlobal(QPoint(100, 100))), &child); + dialog.close(); + }); + + dialog.exec(); } /* |