]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/tests/kfileitemmodeltest.cpp
Exit the deleted directory when it is removed
[dolphin.git] / src / tests / kfileitemmodeltest.cpp
index e9bb7efb78ca8a5760ea1d1f84cbf2b1ebb2d15e..fef8bd58120c682e054bb5185fda753cd4175d78 100644 (file)
@@ -14,7 +14,7 @@
 
 #include <KDirLister>
 #include <kio/job.h>
-#include <KIO/kio_version.h>
+#include <kio_version.h>
 
 
 #include "kitemviews/kfileitemmodel.h"
@@ -93,6 +93,7 @@ private Q_SLOTS:
     void testCreateMimeData();
     void testDeleteFileMoreThanOnce();
     void testInsertAfterExpand();
+    void testCurrentDirRemoved();
 
 private:
     QStringList itemsInModel() const;
@@ -2076,7 +2077,7 @@ void KFileItemModelTest::testInsertAfterExpand()
     QVERIFY(m_model->isExpanded(0));
     QVERIFY(itemsInsertedSpy.wait());
     QCOMPARE(m_model->count(), 2); // 3 items: "a/", "a/a/"
-    QCOMPARE(m_model->expandedDirectories(), {QUrl::fromLocalFile(m_testDir->path() + "/a")});
+    QCOMPARE(m_model->expandedDirectories(), QSet<QUrl>({QUrl::fromLocalFile(m_testDir->path() + "/a")}));
 
     QCOMPARE(itemsInsertedSpy.count(), 1);
     {
@@ -2124,6 +2125,32 @@ void KFileItemModelTest::testInsertAfterExpand()
 
 }
 
+void KFileItemModelTest::testCurrentDirRemoved()
+{
+    m_model->m_dirLister->setAutoUpdate(true);
+    QSignalSpy currentDirectoryRemovedSpy(m_model, &KFileItemModel::currentDirectoryRemoved);
+    QVERIFY(currentDirectoryRemovedSpy.isValid());
+    QSignalSpy loadingCompletedSpy(m_model, &KFileItemModel::directoryLoadingCompleted);
+    QVERIFY(loadingCompletedSpy.isValid());
+    QSignalSpy dirListerClearSpy(m_model->m_dirLister, &KCoreDirLister::clear);
+    QVERIFY(dirListerClearSpy.isValid());
+
+    m_testDir->createFiles({"dir/a.txt", "dir/b.txt"});
+    m_model->loadDirectory(QUrl::fromLocalFile(m_testDir->path() + "/dir/"));
+    QVERIFY(loadingCompletedSpy.wait());
+    QCOMPARE(m_model->count(), 2);
+    QVERIFY(m_model->isConsistent());
+
+    m_testDir->removeDir("dir");
+    QVERIFY(currentDirectoryRemovedSpy.wait());
+
+    // dirLister calls clear
+    QCOMPARE(dirListerClearSpy.count(), 2);
+    QVERIFY(m_model->isConsistent());
+    QVERIFY(m_model->m_itemData.isEmpty());
+    QCOMPARE(m_model->count(), 0);
+}
+
 QStringList KFileItemModelTest::itemsInModel() const
 {
     QStringList items;