diff --git a/kioslave/desktop/tests/kio_desktop_test.cpp b/kioslave/desktop/tests/kio_desktop_test.cpp index 8ced7d155..a2b65f810 100644 --- a/kioslave/desktop/tests/kio_desktop_test.cpp +++ b/kioslave/desktop/tests/kio_desktop_test.cpp @@ -25,6 +25,16 @@ #include #include #include +#include + +static void doUndo() // see FileUndoManagerTest::doUndo() +{ + QEventLoop eventLoop; + QObject::connect(KIO::FileUndoManager::self(), &KIO::FileUndoManager::undoJobFinished, + &eventLoop, &QEventLoop::quit); + KIO::FileUndoManager::self()->undo(); + eventLoop.exec(QEventLoop::ExcludeUserInputEvents); // wait for undo job to finish +} class TestDesktop : public QObject { @@ -167,6 +177,27 @@ private Q_SLOTS: } } + void testTrashAndUndo() + { + // Given a file on the desktop... + const QString localPath = m_desktopPath + '/' + m_testFileName; + QVERIFY(QFile::exists(localPath)); + + // ...moved to the trash + const QUrl desktopUrl("desktop:/" + m_testFileName); + KIO::Job *job = KIO::trash({desktopUrl}, KIO::HideProgressInfo); + job->setUiDelegate(nullptr); + KIO::FileUndoManager::self()->recordJob(KIO::FileUndoManager::Trash, {desktopUrl}, QUrl(QStringLiteral("trash:/")), job); + QVERIFY2(job->exec(), qPrintable(job->errorString())); + QVERIFY(!QFile::exists(localPath)); + + // When the user calls undo + doUndo(); + + // Then the file should re-appear + QVERIFY(QFile::exists(localPath)); + } + private: QString m_desktopPath; QString m_testFileName;