┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src/tests
diff options
context:
space:
mode:
authorFrank Reininghaus <[email protected]>2011-01-16 14:13:30 +0000
committerFrank Reininghaus <[email protected]>2011-01-16 14:13:30 +0000
commitae59d894c2691b02e3ce63707b590ff797d9e7b6 (patch)
tree0853d5e08853c7fae61c3da7c5fc07c5ac50e15e /src/tests
parentd650a50d10f0622e0d548316ba666797f5034190 (diff)
DolphinTreeViewTest: Add unit test for bug 220898 (rubberband
selection failure after a keyboard focus change in between key press and key release events) svn path=/trunk/KDE/kdebase/apps/; revision=1214822
Diffstat (limited to 'src/tests')
-rw-r--r--src/tests/dolphintreeviewtest.cpp79
1 files changed, 78 insertions, 1 deletions
diff --git a/src/tests/dolphintreeviewtest.cpp b/src/tests/dolphintreeviewtest.cpp
index 5aa5376ea..18069125a 100644
--- a/src/tests/dolphintreeviewtest.cpp
+++ b/src/tests/dolphintreeviewtest.cpp
@@ -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"