diff options
| author | Amol Godbole <[email protected]> | 2023-12-23 15:36:31 -0600 |
|---|---|---|
| committer | Méven Car <[email protected]> | 2024-01-14 08:34:58 +0000 |
| commit | 0d2aa8a1bed1cef4a2dd99493dacf40812807cf9 (patch) | |
| tree | f8e2896a9a2032377ad284b0774dfb252f4065ef /src | |
| parent | 5a8bd47296e204a68014a60757758c50fa623526 (diff) | |
DolphinMainWindowTest: Add unit test for autosave session feature
Adds a simple test to check if session is autosaved when a new tab is
opened.
Diffstat (limited to 'src')
| -rw-r--r-- | src/tests/dolphinmainwindowtest.cpp | 39 |
1 files changed, 39 insertions, 0 deletions
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 <KActionCollection> +#include <KConfig> +#include <KConfigGui> #include <QAccessible> +#include <QFileSystemWatcher> #include <QScopedPointer> #include <QSignalSpy> #include <QStandardPaths> @@ -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<DolphinTabWidget *>("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(); |
