X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/aefa8ce888ffe9f8699319314672a6bc42f8d95f..8eb9b508ca87fb1d634d8b8ba62c054ed04466d2:/src/tests/dolphintreeviewtest.cpp?ds=sidebyside diff --git a/src/tests/dolphintreeviewtest.cpp b/src/tests/dolphintreeviewtest.cpp index 5aa5376ea..afcd34d2b 100644 --- a/src/tests/dolphintreeviewtest.cpp +++ b/src/tests/dolphintreeviewtest.cpp @@ -18,14 +18,14 @@ *****************************************************************************/ #include -#include -#include +#include +#include #include "views/dolphintreeview.h" #include #include -#include +#include class DolphinTreeViewTest : public QObject { @@ -36,6 +36,7 @@ private slots: void testKeyboardNavigationSelectionUpdate(); void bug218114_visualRegionForSelection(); + void bug220898_focusOut(); private: @@ -333,6 +334,80 @@ void DolphinTreeViewTest::bug218114_visualRegionForSelection() QVERIFY(boundingRect.contains(view.visualRect(index2))); } +/** + * This test verifies that selection of multiple items with the mouse works + * if a key was pressed and the keyboard focus moved to another window before the + * key was released, see + * + * https://bugs.kde.org/show_bug.cgi?id=220898 + */ + +void DolphinTreeViewTest::bug220898_focusOut() +{ + QStringList items; + items << "a" << "b" << "c" << "d" << "e"; + QStringListModel model(items); + + QModelIndex index[5]; + for (int i = 0; i < 5; i++) { + index[i] = model.index(i, 0); + } + + TestView view; + view.setModel(&model); + view.setSelectionMode(QAbstractItemView::ExtendedSelection); + view.resize(400, 400); + view.show(); + QTest::qWaitForWindowShown(&view); + + view.setCurrentIndex(index[0]); + verifyCurrentItemAndSelection(view, index[0]); + + // Press Down + QTest::keyPress(view.viewport(), Qt::Key_Down, Qt::NoModifier); + + // Move keyboard focus to another widget + QWidget widget; + widget.show(); + QTest::qWaitForWindowShown(&widget); + widget.setFocus(); + + // Wait until the widgets have received the focus events + while (view.viewport()->hasFocus()) { + QTest::qWait(10); + } + QVERIFY(!view.viewport()->hasFocus()); + + // Release the "Down" key + QTest::keyRelease(&widget, Qt::Key_Down, Qt::NoModifier); + + // Move keyboard focus back to the view + widget.hide(); + view.viewport()->setFocus(); + + // Wait until the widgets have received the focus events + while (widget.hasFocus()) { + QTest::qWait(10); + } + QVERIFY(!widget.hasFocus()); + + // Press left mouse button below the last item + const int lastRowHeight = view.sizeHintForRow(4); + QTest::mousePress(view.viewport(), Qt::LeftButton, Qt::NoModifier, view.visualRect(index[4]).center() + QPoint(0, lastRowHeight)); + + // Move mouse to the first item and release + QTest::mouseMove(view.viewport(), view.visualRect(index[0]).center()); + QMouseEvent moveEvent(QEvent::MouseMove, view.visualRect(index[0]).center(), Qt::NoButton, Qt::LeftButton, Qt::NoModifier); + bool moveEventReceived = qApp->notify(view.viewport(), &moveEvent); + QVERIFY(moveEventReceived); + QTest::mouseRelease(view.viewport(), Qt::LeftButton, Qt::NoModifier, view.visualRect(index[0]).center()); + + // All items should be selected + QModelIndexList expectedSelection; + expectedSelection << index[0] << index[1] << index[2] << index[3] << index[4]; + verifyCurrentItemAndSelection(view, index[0], expectedSelection); +} + QTEST_KDEMAIN(DolphinTreeViewTest, GUI) -#include "dolphintreeviewtest.moc" \ No newline at end of file +#include "dolphintreeviewtest.moc"