┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src/tests
diff options
context:
space:
mode:
authorFrank Reininghaus <[email protected]>2011-01-26 13:38:19 +0000
committerFrank Reininghaus <[email protected]>2011-01-26 13:38:19 +0000
commita2ac570198ba2b6cf0708af322aef5d0fe246ae2 (patch)
treeed4eeac75888d02933ce7287987f00732035cf41 /src/tests
parent72fb2ca0a83deef9c1cbd99e45759d4b49f131ad (diff)
Some additions to DolphinDetailsViewTest_AllViewModes.
In particular, tests for changing the zoom level and for saving and restoring the view state. svn path=/trunk/KDE/kdebase/apps/; revision=1217270
Diffstat (limited to 'src/tests')
-rw-r--r--src/tests/CMakeLists.txt8
-rw-r--r--src/tests/dolphinviewtest_allviewmodes.cpp155
-rw-r--r--src/tests/dolphinviewtest_allviewmodes.h2
3 files changed, 159 insertions, 6 deletions
diff --git a/src/tests/CMakeLists.txt b/src/tests/CMakeLists.txt
index 5199c2849..e0d9aa2be 100644
--- a/src/tests/CMakeLists.txt
+++ b/src/tests/CMakeLists.txt
@@ -1,5 +1,5 @@
set( EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR} )
-include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/.. ${KDE4_INCLUDES} )
+include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/.. ${CMAKE_CURRENT_BUILD_DIR}/.. ${KDE4_INCLUDES} )
kde4_add_unit_test(dolphintreeviewtest TEST dolphintreeviewtest.cpp)
target_link_libraries(dolphintreeviewtest dolphinprivate ${KDE4_KDEUI_LIBS} ${QT_QTTEST_LIBRARY})
@@ -7,11 +7,11 @@ target_link_libraries(dolphintreeviewtest dolphinprivate ${KDE4_KDEUI_LIBS} ${QT
kde4_add_unit_test(dolphindetailsviewtest TEST dolphindetailsviewtest.cpp testbase.cpp ../views/zoomlevelinfo.cpp)
target_link_libraries(dolphindetailsviewtest dolphinprivate ${KDE4_KIO_LIBS} ${QT_QTTEST_LIBRARY})
-kde4_add_unit_test(dolphinviewtest_icons TEST dolphinviewtest_icons.cpp dolphinviewtest_allviewmodes.cpp testbase.cpp)
+kde4_add_unit_test(dolphinviewtest_icons TEST dolphinviewtest_icons.cpp dolphinviewtest_allviewmodes.cpp testbase.cpp ../views/zoomlevelinfo.cpp)
target_link_libraries(dolphinviewtest_icons dolphinprivate ${KDE4_KIO_LIBS} ${QT_QTTEST_LIBRARY})
-kde4_add_unit_test(dolphinviewtest_details TEST dolphinviewtest_details.cpp dolphinviewtest_allviewmodes.cpp testbase.cpp)
+kde4_add_unit_test(dolphinviewtest_details TEST dolphinviewtest_details.cpp dolphinviewtest_allviewmodes.cpp testbase.cpp ../views/zoomlevelinfo.cpp)
target_link_libraries(dolphinviewtest_details dolphinprivate ${KDE4_KIO_LIBS} ${QT_QTTEST_LIBRARY})
-kde4_add_unit_test(dolphinviewtest_columns TEST dolphinviewtest_columns.cpp dolphinviewtest_allviewmodes.cpp testbase.cpp)
+kde4_add_unit_test(dolphinviewtest_columns TEST dolphinviewtest_columns.cpp dolphinviewtest_allviewmodes.cpp testbase.cpp ../views/zoomlevelinfo.cpp)
target_link_libraries(dolphinviewtest_columns dolphinprivate ${KDE4_KIO_LIBS} ${QT_QTTEST_LIBRARY})
diff --git a/src/tests/dolphinviewtest_allviewmodes.cpp b/src/tests/dolphinviewtest_allviewmodes.cpp
index 45f4cb56b..fada6c3b5 100644
--- a/src/tests/dolphinviewtest_allviewmodes.cpp
+++ b/src/tests/dolphinviewtest_allviewmodes.cpp
@@ -27,6 +27,9 @@
#include "views/dolphinmodel.h"
#include "views/dolphindirlister.h"
#include "views/dolphinsortfilterproxymodel.h"
+#include "views/zoomlevelinfo.h"
+
+#include <QtGui/QScrollBar>
#include <qtestmouse.h>
#include <qtestkeyboard.h>
@@ -105,15 +108,22 @@ void DolphinViewTest_AllViewModes::testSelection() {
QTest::mouseClick(itemView()->viewport(), Qt::LeftButton, Qt::ControlModifier, itemView()->visualRect(index).center());
verifySelectedItemsCount(1);
- index = itemView()->model()->index(45, 0);
+ index = itemView()->model()->index(totalItems - 5, 0);
itemView()->scrollTo(index);
QTest::mouseClick(itemView()->viewport(), Qt::LeftButton, Qt::ControlModifier, itemView()->visualRect(index).center());
verifySelectedItemsCount(2);
- index = itemView()->model()->index(48, 0);
+ index = itemView()->model()->index(totalItems - 2, 0);
itemView()->scrollTo(index);
QTest::mouseClick(itemView()->viewport(), Qt::LeftButton, Qt::ShiftModifier, itemView()->visualRect(index).center());
verifySelectedItemsCount(5);
+
+ m_view->invertSelection();
+ verifySelectedItemsCount(totalItems - 5);
+
+ // Pressing Esc should clear the selection
+ QTest::keyClick(itemView()->viewport(), Qt::Key_Escape);
+ verifySelectedItemsCount(0);
}
/**
@@ -214,6 +224,147 @@ void DolphinViewTest_AllViewModes::testViewPropertySettings()
}
/**
+ * testZoomLevel() checks that setting the zoom level works, both using DolphinView's API and using Ctrl+mouse wheel.
+ */
+
+void DolphinViewTest_AllViewModes::testZoomLevel()
+{
+ createFiles(QStringList() << "a" << "b");
+ reloadViewAndWait();
+
+ m_view->setShowPreview(false);
+ QVERIFY(!m_view->showPreview());
+
+ int zoomLevelBackup = m_view->zoomLevel();
+
+ int zoomLevel = ZoomLevelInfo::minimumLevel();
+ m_view->setZoomLevel(zoomLevel);
+ QCOMPARE(m_view->zoomLevel(), zoomLevel);
+
+ // Increase the zoom level successively to the maximum.
+ while(zoomLevel < ZoomLevelInfo::maximumLevel()) {
+ zoomLevel++;
+ m_view->setZoomLevel(zoomLevel);
+ QCOMPARE(m_view->zoomLevel(), zoomLevel);
+ }
+
+ // Try setting a zoom level larger than the maximum
+ m_view->setZoomLevel(ZoomLevelInfo::maximumLevel() + 1);
+ QCOMPARE(m_view->zoomLevel(), ZoomLevelInfo::maximumLevel());
+
+ // Turn previews on and try setting a zoom level smaller than the minimum
+ m_view->setShowPreview(true);
+ QVERIFY(m_view->showPreview());
+ m_view->setZoomLevel(ZoomLevelInfo::minimumLevel() - 1);
+ QCOMPARE(m_view->zoomLevel(), ZoomLevelInfo::minimumLevel());
+
+ // Turn previews off again and check that the zoom level is restored
+ m_view->setShowPreview(false);
+ QVERIFY(!m_view->showPreview());
+ QCOMPARE(m_view->zoomLevel(), ZoomLevelInfo::maximumLevel());
+
+ // Change the zoom level using Ctrl+mouse wheel
+ QModelIndex index = itemView()->model()->index(0, 0);
+ itemView()->scrollTo(index);
+
+ while (m_view->zoomLevel() > ZoomLevelInfo::minimumLevel()) {
+ int oldZoomLevel = m_view->zoomLevel();
+ QWheelEvent wheelEvent(itemView()->visualRect(index).center(), -1, Qt::NoButton, Qt::ControlModifier);
+ bool wheelEventReceived = qApp->notify(itemView()->viewport(), &wheelEvent);
+ QVERIFY(wheelEventReceived);
+ QVERIFY(m_view->zoomLevel() < oldZoomLevel);
+ }
+ QCOMPARE(m_view->zoomLevel(), ZoomLevelInfo::minimumLevel());
+
+ while (m_view->zoomLevel() < ZoomLevelInfo::maximumLevel()) {
+ int oldZoomLevel = m_view->zoomLevel();
+ QWheelEvent wheelEvent(itemView()->visualRect(index).center(), 1, Qt::NoButton, Qt::ControlModifier);
+ bool wheelEventReceived = qApp->notify(itemView()->viewport(), &wheelEvent);
+ QVERIFY(wheelEventReceived);
+ QVERIFY(m_view->zoomLevel() > oldZoomLevel);
+ }
+ QCOMPARE(m_view->zoomLevel(), ZoomLevelInfo::maximumLevel());
+
+ // Turn previews on again and check that the zoom level is restored
+ m_view->setShowPreview(true);
+ QVERIFY(m_view->showPreview());
+ QCOMPARE(m_view->zoomLevel(), ZoomLevelInfo::minimumLevel());
+
+ // Restore the initial state
+ m_view->setZoomLevel(zoomLevelBackup);
+ m_view->setShowPreview(false);
+ m_view->setZoomLevel(zoomLevelBackup);
+}
+
+/**
+ * testSaveAndRestoreState() checks if saving and restoring the view state (current item, scroll position).
+ *
+ * Note that we call qApp->sendPostedEvents() every time the view's finishedPathLoading(const KUrl&) signal
+ * is received. The reason is that the scroll position is restored in the slot restoreContentsPosition(),
+ * which is been invoked using a queued connection in DolphinView::slotLoadingCompleted(). To make sure
+ * that this slot is really executed before we proceed, we have to empty the event queue using qApp->sendPostedEvents().
+ */
+
+void DolphinViewTest_AllViewModes::testSaveAndRestoreState()
+{
+ const int totalItems = 50;
+
+ for (int i = 0; i < totalItems; i++) {
+ createFile(QString("%1").arg(i));
+ }
+ createDir("51");
+ reloadViewAndWait();
+
+ // Set sorting settings to the default to make sure that the item positions are reproducible.
+ m_view->setSorting(DolphinView::SortByName);
+ QCOMPARE(m_view->sorting(), DolphinView::SortByName);
+ m_view->setSortOrder(Qt::AscendingOrder);
+ QCOMPARE(m_view->sortOrder(), Qt::AscendingOrder);
+
+ const QModelIndex index45 = itemView()->model()->index(45, 0);
+ itemView()->scrollTo(index45);
+ itemView()->setCurrentIndex(index45);
+ const int scrollPosX = itemView()->horizontalScrollBar()->value();
+ const int scrollPosY = itemView()->verticalScrollBar()->value();
+
+ // Save the view state
+ QByteArray viewState;
+ QDataStream saveStream(&viewState, QIODevice::WriteOnly);
+ m_view->saveState(saveStream);
+
+ // Change the URL and then go back
+ m_view->setUrl(m_path + "/51");
+ QVERIFY(QTest::kWaitForSignal(m_view, SIGNAL(finishedPathLoading(const KUrl&)), 2000));
+ qApp->sendPostedEvents();
+
+ m_view->setUrl(m_path);
+ QVERIFY(QTest::kWaitForSignal(m_view, SIGNAL(finishedPathLoading(const KUrl&)), 2000));
+ qApp->sendPostedEvents();
+
+ // Verify that the view is scrolled to top and that item 45 is not the current item
+ QVERIFY(itemView()->currentIndex() != index45);
+ QCOMPARE(itemView()->horizontalScrollBar()->value(), 0);
+ QCOMPARE(itemView()->verticalScrollBar()->value(), 0);
+
+ // Change the URL again
+ m_view->setUrl(m_path + "/51");
+ QVERIFY(QTest::kWaitForSignal(m_view, SIGNAL(finishedPathLoading(const KUrl&)), 2000));
+ qApp->sendPostedEvents();
+
+ // Check that the current item and scroll position are correct if DolphinView::restoreState()
+ // is called after the URL change
+ m_view->setUrl(m_path);
+ QDataStream restoreStream(viewState);
+ m_view->restoreState(restoreStream);
+ QVERIFY(QTest::kWaitForSignal(m_view, SIGNAL(finishedPathLoading(const KUrl&)), 2000));
+ qApp->sendPostedEvents();
+
+ QCOMPARE(itemView()->currentIndex(), index45);
+ QCOMPARE(itemView()->horizontalScrollBar()->value(), scrollPosX);
+ QCOMPARE(itemView()->verticalScrollBar()->value(), scrollPosY);
+}
+
+/**
* testKeyboardFocus() checks whether a view grabs the keyboard focus.
*
* A view may never grab the keyboard focus itself and must respect the focus-state
diff --git a/src/tests/dolphinviewtest_allviewmodes.h b/src/tests/dolphinviewtest_allviewmodes.h
index 690459584..c8ea61002 100644
--- a/src/tests/dolphinviewtest_allviewmodes.h
+++ b/src/tests/dolphinviewtest_allviewmodes.h
@@ -50,6 +50,8 @@ private slots:
void testSelection();
void testViewPropertySettings();
+ void testZoomLevel();
+ void testSaveAndRestoreState();
void testKeyboardFocus();