]> cloud.milkyroute.net Git - dolphin.git/commitdiff
DolphinTreeViewTest: Add unit test for bug 220898 (rubberband
authorFrank Reininghaus <frank78ac@googlemail.com>
Sun, 16 Jan 2011 14:13:30 +0000 (14:13 +0000)
committerFrank Reininghaus <frank78ac@googlemail.com>
Sun, 16 Jan 2011 14:13:30 +0000 (14:13 +0000)
selection failure after a keyboard focus change in between key press
and key release events)

svn path=/trunk/KDE/kdebase/apps/; revision=1214822

src/tests/dolphintreeviewtest.cpp

index 5aa5376eaffbb303fc8bf026f5c0fe5821d3f33a..18069125a62eddb5692be601cf0ab9913fb50132 100644 (file)
@@ -36,6 +36,7 @@ private slots:
     void testKeyboardNavigationSelectionUpdate();
 
     void bug218114_visualRegionForSelection();
+    void bug220898_focusOut();
 
 private:
 
@@ -333,6 +334,82 @@ 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() || !widget.hasFocus()) {
+        QTest::qWait(10);
+    }
+    QVERIFY(widget.hasFocus());
+    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 (!view.viewport()->hasFocus() || widget.hasFocus()) {
+        QTest::qWait(10);
+    }
+    QVERIFY(!widget.hasFocus());
+    QVERIFY(view.viewport()->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"