From a18ab2a3822e0d38e8ff19ccdf44d9fc802b5d02 Mon Sep 17 00:00:00 2001 From: Frederik Gladhorn Date: Thu, 2 Aug 2018 08:40:04 +0200 Subject: Protect tab focus chain from infinite loops when item is invisible Make sure to start the search for a potential focus item on an item that will be visited again later, otherwise we'll loop for ever. Fixes: QTBUG-68271 Change-Id: Icb330e4e726132511810027a33b9fb346c7fa131 Reviewed-by: Shawn Rutledge Reviewed-by: Gabriel de Dietrich --- tests/auto/quick/qquickitem2/tst_qquickitem.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'tests/auto/quick/qquickitem2/tst_qquickitem.cpp') diff --git a/tests/auto/quick/qquickitem2/tst_qquickitem.cpp b/tests/auto/quick/qquickitem2/tst_qquickitem.cpp index f0f5873ace..7107f4d995 100644 --- a/tests/auto/quick/qquickitem2/tst_qquickitem.cpp +++ b/tests/auto/quick/qquickitem2/tst_qquickitem.cpp @@ -64,6 +64,7 @@ private slots: void activeFocusOnTab8(); void activeFocusOnTab9(); void activeFocusOnTab10(); + void activeFocusOnTab_infiniteLoop(); void nextItemInFocusChain(); void nextItemInFocusChain2(); @@ -1023,6 +1024,22 @@ void tst_QQuickItem::activeFocusOnTab10() delete window; } +void tst_QQuickItem::activeFocusOnTab_infiniteLoop() +{ + // see QTBUG-68271 + // create a window where the currently focused item is not visible + QScopedPointerwindow(new QQuickView()); + window->setSource(testFileUrl("activeFocusOnTab_infiniteLoop.qml")); + window->show(); + auto *hiddenChild = findItem(window->rootObject(), "hiddenChild"); + QVERIFY(hiddenChild); + + // move the focus - this used to result in an infinite loop + auto *item = hiddenChild->nextItemInFocusChain(); + // focus is moved to the root object since there is no other candidate + QCOMPARE(item, window->rootObject()); +} + void tst_QQuickItem::nextItemInFocusChain() { if (!qt_tab_all_widgets()) -- cgit v1.2.3