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

See KIO commit 994d9030d2e3f60 in KF 5.62

CCBUG: 391606
wilder-5.18
David Faure 6 years ago
parent 909f9145e7
commit 4d216b0a01
  1. 31
      kioslave/desktop/tests/kio_desktop_test.cpp

@ -25,6 +25,16 @@
#include <QTest>
#include <kio/job.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
{
@ -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;

Loading…
Cancel
Save