From 0d2aa8a1bed1cef4a2dd99493dacf40812807cf9 Mon Sep 17 00:00:00 2001 From: Amol Godbole Date: Sat, 23 Dec 2023 15:36:31 -0600 Subject: [PATCH] DolphinMainWindowTest: Add unit test for autosave session feature Adds a simple test to check if session is autosaved when a new tab is opened. --- src/tests/dolphinmainwindowtest.cpp | 39 +++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/tests/dolphinmainwindowtest.cpp b/src/tests/dolphinmainwindowtest.cpp index e6c355a87..60d46518a 100644 --- a/src/tests/dolphinmainwindowtest.cpp +++ b/src/tests/dolphinmainwindowtest.cpp @@ -13,8 +13,11 @@ #include "testdir.h" #include +#include +#include #include +#include #include #include #include @@ -43,6 +46,7 @@ private Q_SLOTS: void testGoActions(); void testOpenFiles(); void testAccessibilityAncestorTree(); + void testAutoSaveSession(); void cleanupTestCase(); private: @@ -561,6 +565,41 @@ void DolphinMainWindowTest::testAccessibilityAncestorTree() } } +void DolphinMainWindowTest::testAutoSaveSession() +{ + m_mainWindow->openDirectories({QUrl::fromLocalFile(QDir::homePath())}, false); + m_mainWindow->show(); + QVERIFY(QTest::qWaitForWindowExposed(m_mainWindow.data())); + QVERIFY(m_mainWindow->isVisible()); + + // Create config file + KConfigGui::setSessionConfig(QStringLiteral("dolphin"), QStringLiteral("dolphin")); + KConfig *config = KConfigGui::sessionConfig(); + m_mainWindow->saveGlobalProperties(config); + m_mainWindow->savePropertiesInternal(config, 1); + config->sync(); + + // Setup watcher for config file changes + const QString configFileName = QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) + "/" + KConfigGui::sessionConfig()->name(); + QFileSystemWatcher *configWatcher = new QFileSystemWatcher({configFileName}, this); + QSignalSpy spySessionSaved(configWatcher, &QFileSystemWatcher::fileChanged); + + // Enable session autosave. + m_mainWindow->setSessionAutoSaveEnabled(true); + + // Open a new tab + auto tabWidget = m_mainWindow->findChild("tabWidget"); + QVERIFY(tabWidget); + tabWidget->openNewActivatedTab(QUrl::fromLocalFile(QDir::tempPath())); + QCOMPARE(tabWidget->count(), 2); + + // Wait till a session save occurs + QVERIFY(spySessionSaved.wait(60000)); + + // Disable session autosave. + m_mainWindow->setSessionAutoSaveEnabled(false); +} + void DolphinMainWindowTest::cleanupTestCase() { m_mainWindow->showNormal(); -- 2.47.3