Commit 4d216b0a authored by David Faure's avatar David Faure
Browse files

Add unittest for KIO fix for undoing trashing files from the desktop

See KIO commit 994d9030d2e3f60 in KF 5.62

CCBUG: 391606
parent 909f9145
...@@ -25,6 +25,16 @@ ...@@ -25,6 +25,16 @@
#include <QTest> #include <QTest>
#include <kio/job.h> #include <kio/job.h>
#include <kio/copyjob.h> #include <kio/copyjob.h>
#include <KIO/FileUndoManager>
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 class TestDesktop : public QObject
{ {
...@@ -167,6 +177,27 @@ private Q_SLOTS: ...@@ -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: private:
QString m_desktopPath; QString m_desktopPath;
QString m_testFileName; QString m_testFileName;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment