summaryrefslogtreecommitdiffstats
path: root/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp
diff options
context:
space:
mode:
authorGatis Paeglis <gatis.paeglis@qt.io>2017-10-30 16:42:57 +0100
committerGatis Paeglis <gatis.paeglis@qt.io>2018-04-25 13:07:23 +0000
commitd50d35d9db698f13aaf98a118713a4a1c74d1bd4 (patch)
treead8369c87f71fc050465350098255eee4a75b141 /tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp
parent98ef4239a6b859522a45bdd03ba5496ea201e5f3 (diff)
tests: cleanup tst_QComboBox::keyBoardNavigationWithMouse()
- Don't use QCursor when we can position a mouse relative to the window coordinates via QTest::mouse*() functions. Even the way QCursor was user here seemed to be hackish. This hack apparently was there to make the test pass on macOS, I have verified that the updated test continue working on this platform. - Remove Q_OS_QNX ifdef, as this test does not depend on QCursor anymore. - Remove QTest::qWait()-s. Unconditinal waiting should not be used. - Add better comments. - Other minor things. And move tst_QComboBox to use QTEST_QPA_MOUSE_HANDLING code path. Eventually we want to deprecate the legacy code path. Change-Id: Ib72f324b5197d0fd66fc32b8c1c7509e58838e04 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Diffstat (limited to 'tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp')
-rw-r--r--tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp38
1 files changed, 7 insertions, 31 deletions
diff --git a/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp b/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp
index 0c229c9194..37f0864213 100644
--- a/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp
+++ b/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp
@@ -2722,32 +2722,18 @@ void tst_QComboBox::resetModel()
}
-static inline void centerCursor(const QWidget *w)
-{
-#ifndef QT_NO_CURSOR
- // Force cursor movement to prevent QCursor::setPos() from returning prematurely on QPA:
- const QPoint target(w->mapToGlobal(w->rect().center()));
- QCursor::setPos(QPoint(target.x() + 1, target.y()));
- QCursor::setPos(target);
-#else // !QT_NO_CURSOR
- Q_UNUSED(w)
-#endif
-}
-
void tst_QComboBox::keyBoardNavigationWithMouse()
{
QComboBox combo;
combo.setEditable(false);
setFrameless(&combo);
- combo.move(200, 200);
- for (int i = 0; i < 80; i++)
- combo.addItem( QString::number(i));
+ for (int i = 0; i < 200; i++)
+ combo.addItem(QString::number(i));
+ combo.move(200, 200);
combo.showNormal();
- centerCursor(&combo); // QTBUG-33973, cursor needs to be within view from start on Mac.
QApplication::setActiveWindow(&combo);
QVERIFY(QTest::qWaitForWindowActive(&combo));
- QCOMPARE(QApplication::activeWindow(), static_cast<QWidget *>(&combo));
QCOMPARE(combo.currentText(), QLatin1String("0"));
@@ -2755,18 +2741,12 @@ void tst_QComboBox::keyBoardNavigationWithMouse()
QTRY_VERIFY(combo.hasFocus());
QTest::keyClick(combo.lineEdit(), Qt::Key_Space);
- QTest::qWait(30);
QTRY_VERIFY(combo.view());
QTRY_VERIFY(combo.view()->isVisible());
- QTest::qWait(130);
QCOMPARE(combo.currentText(), QLatin1String("0"));
- // When calling cursor function, Windows CE responds with: This function is not supported on this system.
-#if !defined Q_OS_QNX
- // Force cursor movement to prevent QCursor::setPos() from returning prematurely on QPA:
- centerCursor(combo.view());
- QTest::qWait(200);
+ QTest::mouseMove(&combo, combo.rect().center());
#define GET_SELECTION(SEL) \
QCOMPARE(combo.view()->selectionModel()->selection().count(), 1); \
@@ -2774,23 +2754,19 @@ void tst_QComboBox::keyBoardNavigationWithMouse()
SEL = combo.view()->selectionModel()->selection().indexes().first().row()
int selection;
- GET_SELECTION(selection);
-
- //since we moved the mouse is in the middle it should even be around 5;
- QVERIFY2(selection > 3, (QByteArrayLiteral("selection=") + QByteArray::number(selection)).constData());
+ GET_SELECTION(selection); // get initial selection
- static const int final = 40;
+ const int final = 40;
for (int i = selection + 1; i <= final; i++)
{
QTest::keyClick(combo.view(), Qt::Key_Down);
- QTest::qWait(20);
GET_SELECTION(selection);
QCOMPARE(selection, i);
}
QTest::keyClick(combo.view(), Qt::Key_Enter);
QTRY_COMPARE(combo.currentText(), QString::number(final));
-#endif
+#undef GET_SELECTION
}
void tst_QComboBox::task_QTBUG_1071_changingFocusEmitsActivated()