summaryrefslogtreecommitdiffstats
path: root/tests/auto/widgets/util/qcompleter/tst_qcompleter.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/widgets/util/qcompleter/tst_qcompleter.cpp')
-rw-r--r--tests/auto/widgets/util/qcompleter/tst_qcompleter.cpp106
1 files changed, 82 insertions, 24 deletions
diff --git a/tests/auto/widgets/util/qcompleter/tst_qcompleter.cpp b/tests/auto/widgets/util/qcompleter/tst_qcompleter.cpp
index 2f7fb92dc2..b2e77bc935 100644
--- a/tests/auto/widgets/util/qcompleter/tst_qcompleter.cpp
+++ b/tests/auto/widgets/util/qcompleter/tst_qcompleter.cpp
@@ -1,11 +1,10 @@
// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
#include <QtGui>
#include <QtWidgets>
#include <QtDebug>
-#include <QPair>
#include <QList>
#include <QPointer>
#include <QSignalSpy>
@@ -59,7 +58,7 @@ QString CsvCompleter::pathFromIndex(const QModelIndex &sourceIndex) const
idx = parent.sibling(parent.row(), sourceIndex.column());
} while (idx.isValid());
- return list.count() == 1 ? list.constFirst() : list.join(QLatin1Char(','));
+ return list.size() == 1 ? list.constFirst() : list.join(QLatin1Char(','));
}
class tst_QCompleter : public QObject
@@ -110,6 +109,8 @@ private slots:
void dynamicSortOrder();
void disabledItems();
+ void hideWidget();
+
// task-specific tests below me
void task178797_activatedOnReturn();
void task189564_omitNonSelectableItems();
@@ -123,6 +124,7 @@ private slots:
void QTBUG_52028_tabAutoCompletes();
void QTBUG_51889_activatedSentTwice();
void showPopupInGraphicsView();
+ void inheritedEventFilter();
private:
void filter(bool assync = false);
@@ -1060,7 +1062,6 @@ void tst_QCompleter::multipleWidgets()
window.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
window.move(200, 200);
window.show();
- QApplicationPrivate::setActiveWindow(&window);
QVERIFY(QTest::qWaitForWindowActive(&window));
QFocusEvent focusIn(QEvent::FocusIn);
@@ -1072,7 +1073,6 @@ void tst_QCompleter::multipleWidgets()
comboBox->setFocus();
comboBox->show();
window.activateWindow();
- QApplicationPrivate::setActiveWindow(&window);
QVERIFY(QTest::qWaitForWindowActive(&window));
QCOMPARE(QApplication::focusWidget(), comboBox);
comboBox->lineEdit()->setText("it");
@@ -1107,7 +1107,6 @@ void tst_QCompleter::focusIn()
window.move(200, 200);
window.show();
window.activateWindow();
- QApplicationPrivate::setActiveWindow(&window);
QVERIFY(QTest::qWaitForWindowActive(&window));
auto comboBox = new QComboBox(&window);
@@ -1178,13 +1177,39 @@ void tst_QCompleter::disabledItems()
QAbstractItemView *view = lineEdit.completer()->popup();
QVERIFY(view->isVisible());
QTest::mouseClick(view->viewport(), Qt::LeftButton, {}, view->visualRect(view->model()->index(0, 0)).center());
- QCOMPARE(spy.count(), 0);
+ QCOMPARE(spy.size(), 0);
QVERIFY(view->isVisible());
QTest::mouseClick(view->viewport(), Qt::LeftButton, {}, view->visualRect(view->model()->index(1, 0)).center());
- QCOMPARE(spy.count(), 1);
+ QCOMPARE(spy.size(), 1);
QVERIFY(!view->isVisible());
}
+void tst_QCompleter::hideWidget()
+{
+ // hiding the widget should hide/close the popup
+ QWidget w;
+ w.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
+ w.setLayout(new QVBoxLayout);
+
+ QLineEdit edit;
+ edit.setCompleter(new QCompleter({ "foo", "bar" }));
+
+ w.layout()->addWidget(&edit);
+
+ const auto pos = w.screen()->availableGeometry().topLeft() + QPoint(200, 200);
+ w.move(pos);
+ w.show();
+ QApplicationPrivate::setActiveWindow(&w);
+ QVERIFY(QTest::qWaitForWindowActive(&w));
+
+ // activate the completer
+ QTest::keyClick(&edit, Qt::Key_F);
+ QVERIFY(edit.completer()->popup());
+ QTRY_VERIFY(edit.completer()->popup()->isVisible());
+ edit.hide();
+ QVERIFY(!edit.completer()->popup()->isVisible());
+}
+
void tst_QCompleter::task178797_activatedOnReturn()
{
if (QGuiApplication::platformName().startsWith(QLatin1String("wayland"), Qt::CaseInsensitive))
@@ -1195,10 +1220,9 @@ void tst_QCompleter::task178797_activatedOnReturn()
auto completer = new QCompleter({"foobar1", "foobar2"}, &ledit);
ledit.setCompleter(completer);
QSignalSpy spy(completer, QOverload<const QString &>::of(&QCompleter::activated));
- QCOMPARE(spy.count(), 0);
+ QCOMPARE(spy.size(), 0);
ledit.move(200, 200);
ledit.show();
- QApplicationPrivate::setActiveWindow(&ledit);
QVERIFY(QTest::qWaitForWindowActive(&ledit));
QTest::keyClick(&ledit, Qt::Key_F);
QCoreApplication::processEvents();
@@ -1207,7 +1231,7 @@ void tst_QCompleter::task178797_activatedOnReturn()
QCoreApplication::processEvents();
QTest::keyClick(QApplication::activePopupWidget(), Qt::Key_Return);
QCoreApplication::processEvents();
- QCOMPARE(spy.count(), 1);
+ QCOMPARE(spy.size(), 1);
}
class task189564_StringListModel : public QStringListModel
@@ -1282,14 +1306,13 @@ void tst_QCompleter::task246056_setCompletionPrefix()
comboBox.addItem("a2");
comboBox.move(200, 200);
comboBox.show();
- QApplicationPrivate::setActiveWindow(&comboBox);
QVERIFY(QTest::qWaitForWindowActive(&comboBox));
QSignalSpy spy(comboBox.completer(), QOverload<const QModelIndex &>::of(&QCompleter::activated));
QTest::keyPress(&comboBox, 'a');
QTest::keyPress(comboBox.completer()->popup(), Qt::Key_Down);
QTest::keyPress(comboBox.completer()->popup(), Qt::Key_Down);
QTest::keyPress(comboBox.completer()->popup(), Qt::Key_Enter); // don't crash!
- QCOMPARE(spy.count(), 1);
+ QCOMPARE(spy.size(), 1);
const auto index = spy.at(0).constFirst().toModelIndex();
QVERIFY(!index.isValid());
}
@@ -1348,7 +1371,6 @@ void tst_QCompleter::task250064_lostFocus()
task250064_Widget widget;
widget.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
widget.show();
- QApplicationPrivate::setActiveWindow(&widget);
QVERIFY(QTest::qWaitForWindowActive(&widget));
QTest::keyPress(widget.textEdit(), 'a');
Qt::FocusPolicy origPolicy = widget.textEdit()->focusPolicy();
@@ -1393,7 +1415,6 @@ void tst_QCompleter::task253125_lineEditCompletion()
edit.move(200, 200);
edit.show();
edit.setFocus();
- QApplicationPrivate::setActiveWindow(&edit);
QVERIFY(QTest::qWaitForWindowActive(&edit));
QTest::keyClick(&edit, 'i');
@@ -1556,7 +1577,6 @@ void tst_QCompleter::task247560_keyboardNavigation()
edit.move(200, 200);
edit.show();
edit.setFocus();
- QApplicationPrivate::setActiveWindow(&edit);
QVERIFY(QTest::qWaitForWindowActive(&edit));
QTest::keyClick(&edit, 'r');
@@ -1670,7 +1690,6 @@ void tst_QCompleter::QTBUG_14292_filesystem()
edit.move(200, 200);
edit.show();
- QApplicationPrivate::setActiveWindow(&edit);
QVERIFY(QTest::qWaitForWindowActive(&edit));
QCOMPARE(QApplication::activeWindow(), &edit);
edit.setFocus();
@@ -1686,6 +1705,7 @@ void tst_QCompleter::QTBUG_14292_filesystem()
QTRY_VERIFY(comp.popup()->isVisible());
QCOMPARE(comp.popup()->model()->rowCount(), 2);
QApplication::processEvents();
+ QCOMPARE(qApp->focusObject(), &edit); // for QTBUG_108522
QTest::keyClick(&edit, 'h');
QCOMPARE(comp.popup()->model()->rowCount(), 2);
QTest::keyClick(&edit, 'e');
@@ -1714,7 +1734,6 @@ void tst_QCompleter::QTBUG_14292_filesystem()
QWidget w;
w.move(400, 200);
w.show();
- QApplicationPrivate::setActiveWindow(&w);
QVERIFY(QTest::qWaitForWindowActive(&w));
QVERIFY(!edit.hasFocus() && !comp.popup()->hasFocus());
@@ -1763,10 +1782,10 @@ void tst_QCompleter::QTBUG_52028_tabAutoCompletes()
QTRY_VERIFY(cbox.completer()->popup()->isVisible());
QTest::keyClick(cbox.completer()->popup(), Qt::Key_Tab);
QCOMPARE(cbox.completer()->currentCompletion(), QLatin1String("hux"));
- QCOMPARE(activatedSpy.count(), 0);
+ QCOMPARE(activatedSpy.size(), 0);
QEXPECT_FAIL("", "QTBUG-52028 will not be fixed today.", Abort);
QCOMPARE(cbox.currentText(), QLatin1String("hux"));
- QCOMPARE(activatedSpy.count(), 0);
+ QCOMPARE(activatedSpy.size(), 0);
QVERIFY(!le->hasFocus());
}
@@ -1795,7 +1814,6 @@ void tst_QCompleter::QTBUG_51889_activatedSentTwice()
const auto pos = w.screen()->availableGeometry().topLeft() + QPoint(200,200);
w.move(pos);
w.show();
- QApplicationPrivate::setActiveWindow(&w);
QVERIFY(QTest::qWaitForWindowActive(&w));
QSignalSpy activatedSpy(&cbox, &QComboBox::activated);
@@ -1807,7 +1825,7 @@ void tst_QCompleter::QTBUG_51889_activatedSentTwice()
QTRY_VERIFY(cbox.completer()->popup()->isVisible());
QTest::keyClick(cbox.completer()->popup(), Qt::Key_Down);
QTest::keyClick(cbox.completer()->popup(), Qt::Key_Return);
- QTRY_COMPARE(activatedSpy.count(), 1);
+ QTRY_COMPARE(activatedSpy.size(), 1);
// Navigate + enter activates only once (non-first item)
cbox.lineEdit()->clear();
@@ -1817,7 +1835,7 @@ void tst_QCompleter::QTBUG_51889_activatedSentTwice()
QTRY_VERIFY(cbox.completer()->popup()->isVisible());
QTest::keyClick(cbox.completer()->popup(), Qt::Key_Down);
QTest::keyClick(cbox.completer()->popup(), Qt::Key_Return);
- QTRY_COMPARE(activatedSpy.count(), 1);
+ QTRY_COMPARE(activatedSpy.size(), 1);
// Full text + enter activates only once
cbox.lineEdit()->clear();
@@ -1826,11 +1844,14 @@ void tst_QCompleter::QTBUG_51889_activatedSentTwice()
QVERIFY(cbox.completer()->popup());
QTRY_VERIFY(cbox.completer()->popup()->isVisible());
QTest::keyClick(&cbox, Qt::Key_Return);
- QTRY_COMPARE(activatedSpy.count(), 1);
+ QTRY_COMPARE(activatedSpy.size(), 1);
}
void tst_QCompleter::showPopupInGraphicsView()
{
+ if (QGuiApplication::platformName().startsWith(QLatin1String("wayland"), Qt::CaseInsensitive))
+ QSKIP("Wayland: Skip this test, see also QTBUG-107186");
+
QGraphicsView view;
QGraphicsScene scene;
view.setScene(&scene);
@@ -1860,5 +1881,42 @@ void tst_QCompleter::showPopupInGraphicsView()
QVERIFY(lineEdit.completer()->popup()->geometry().bottom() < lineEdit.mapToGlobal(QPoint(0, 0)).y());
}
+void tst_QCompleter::inheritedEventFilter()
+{
+ class Completer : public QCompleter
+ {
+ public:
+ explicit Completer(QWidget *parent) : QCompleter(parent)
+ {
+ Q_ASSERT(parent);
+ setPopup(new QListView());
+ popup()->installEventFilter(this);
+ }
+
+ bool m_popupChildAdded = false;
+
+ protected:
+ bool eventFilter(QObject *watched, QEvent *event) override
+ {
+ if (watched == popup() && event->type() == QEvent::ChildAdded)
+ m_popupChildAdded = true;
+
+ return QCompleter::eventFilter(watched, event);
+ }
+ };
+
+ QComboBox comboBox;
+ comboBox.setEditable(true);
+ Completer *completer = new Completer(&comboBox);
+ comboBox.setCompleter(completer);
+
+ // comboBox.show() must not crash with an infinite loop in the event filter
+ comboBox.show();
+ QVERIFY(QTest::qWaitForWindowExposed(&comboBox));
+
+ // Since event orders are platform dependent, only the the ChildAdded event is checked.
+ QVERIFY(QTest::qWaitFor([completer](){return completer->m_popupChildAdded; }));
+}
+
QTEST_MAIN(tst_QCompleter)
#include "tst_qcompleter.moc"