diff --git a/autotests/kmainwindow_unittest.h b/autotests/kmainwindow_unittest.h --- a/autotests/kmainwindow_unittest.h +++ b/autotests/kmainwindow_unittest.h @@ -37,6 +37,7 @@ void testAutoSaveSettings(); void testNoAutoSave(); void testWidgetWithStatusBar(); + void testNativeWidgetSaveSettings(); void testDeleteOnClose(); }; diff --git a/autotests/kmainwindow_unittest.cpp b/autotests/kmainwindow_unittest.cpp --- a/autotests/kmainwindow_unittest.cpp +++ b/autotests/kmainwindow_unittest.cpp @@ -26,6 +26,7 @@ #include #include #include +#include QTEST_MAIN(KMainWindow_UnitTest) @@ -226,3 +227,70 @@ QStatusBar *frameStatusBar = new QStatusBar(frame1); QVERIFY(mw.statusBar() != frameStatusBar); } + + +class NativeMainWindow : public KMainWindow +{ +public: + NativeMainWindow() : KMainWindow() + { + m_dock = new QDockWidget(QStringLiteral("dock"), this); + m_dock->setObjectName(QStringLiteral("dock")); + m_dock->setAllowedAreas(Qt::AllDockWidgetAreas); + m_dock->setFeatures(QDockWidget::DockWidgetMovable); + m_dock->setFloating(false); + + QWidget *w = new QWidget(m_dock); + + m_dock->setWidget(w); + addDockWidget(Qt::RightDockWidgetArea, m_dock); + + setCentralWidget(new QWidget(this)); + + show(); + + setAutoSaveSettings(QStringLiteral("NativeWidgetTestGroup")); + + w->setAttribute(Qt::WA_NativeWindow); + } + + QDockWidget *m_dock; +}; + +void KMainWindow_UnitTest::testNativeWidgetSaveSettings() +{ + { + QEventLoop el; + NativeMainWindow *mw = new NativeMainWindow(); + connect(mw, &QObject::destroyed, &el, &QEventLoop::quit); // quit event loop when window's gone + + QApplication::postEvent(mw, new QDeferredDeleteEvent); + + el.exec(); + } + + { + QEventLoop el; + NativeMainWindow *mw = new NativeMainWindow(); + connect(mw, &QObject::destroyed, &el, &QEventLoop::quit); + + QCOMPARE(mw->m_dock->isHidden(), false); + mw->m_dock->hide(); + + QApplication::postEvent(mw, new QDeferredDeleteEvent); + + el.exec(); + } + + { + QEventLoop el; + NativeMainWindow *mw = new NativeMainWindow(); + connect(mw, &QObject::destroyed, &el, &QEventLoop::quit); + + QVERIFY(mw->m_dock->isHidden()); + + QApplication::postEvent(mw, new QDeferredDeleteEvent); + + el.exec(); + } +}