]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Add unit test for bug 270437
authorFrank Reininghaus <frank78ac@googlemail.com>
Sun, 10 Apr 2011 19:27:15 +0000 (21:27 +0200)
committerFrank Reininghaus <frank78ac@googlemail.com>
Sun, 10 Apr 2011 19:27:15 +0000 (21:27 +0200)
Verify that the current item and the scroll position of the view do not
change if previews are turned off. Actually, the bug was in
KFilePreviewGenerator, but it's easier to test this here.

src/tests/dolphinviewtest_allviewmodes.cpp

index d9db5b141e82ca6ca69198f2803a318596df012f..b5689cb129a7f555a3076be2835d842f05064a7e 100644 (file)
@@ -310,6 +310,15 @@ void DolphinViewTest_AllViewModes::testSaveAndRestoreState()
     view.setSortOrder(Qt::AscendingOrder);
     QCOMPARE(view.sortOrder(), Qt::AscendingOrder);
 
+    // Make sure that previews are off and that the icon size does not depend on the preview setting.
+    // This is needed for the test for bug 270437, see below.
+    view.setShowPreview(false);
+    int zoomLevel = view.zoomLevel();
+    view.setShowPreview(true);
+    view.setZoomLevel(zoomLevel);
+    view.setShowPreview(false);
+
+    // Select item 45
     const QModelIndex index45 = itemView(&view)->model()->index(45, 0);
     itemView(&view)->scrollTo(index45);
     itemView(&view)->setCurrentIndex(index45);
@@ -356,6 +365,39 @@ void DolphinViewTest_AllViewModes::testSaveAndRestoreState()
     QCOMPARE(itemView(&view)->currentIndex(), index45);
     QCOMPARE(itemView(&view)->horizontalScrollBar()->value(), scrollPosX);
     QCOMPARE(itemView(&view)->verticalScrollBar()->value(), scrollPosY);
+
+    /**
+     * Additionally, we verify the fix for the bug https://bugs.kde.org/show_bug.cgi?id=270437
+     * Actually, it's a bug in KFilePreviewGenerator, but it is easier to test it here.
+     */
+
+    // Turn previews on.
+    view.setShowPreview(true);
+    QVERIFY(view.showPreview());
+
+    // We have to process all events in the queue to make sure that previews are really on.
+    qApp->sendPostedEvents();
+
+    // Current item and scroll position should not change.
+    QCOMPARE(itemView(&view)->currentIndex(), index45);
+    QCOMPARE(itemView(&view)->horizontalScrollBar()->value(), scrollPosX);
+    QCOMPARE(itemView(&view)->verticalScrollBar()->value(), scrollPosY);
+
+    // Turn previews off again. Before bug 270437, this triggered the dir lister's openUrl() method
+    // -> we check that by listening to the view's startedPathLoading() signal and wait until the loading is finished in that case.
+    QSignalSpy spy(&view, SIGNAL(startedPathLoading(const KUrl&)));
+    view.setShowPreview(false);
+    QVERIFY(!view.showPreview());
+    qApp->sendPostedEvents();
+    if (!spy.isEmpty()) {
+        // The dir lister reloads the directory. We wait until the loading is finished.
+        QVERIFY(waitForFinishedPathLoading(&view));
+    }
+
+    // Current item and scroll position should not change.
+    QCOMPARE(itemView(&view)->currentIndex(), index45);
+    QCOMPARE(itemView(&view)->horizontalScrollBar()->value(), scrollPosX);
+    QCOMPARE(itemView(&view)->verticalScrollBar()->value(), scrollPosY);
 }
 
 /**