From 2b8e571f8458a533d1b902fff5a812db427b7da0 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Thu, 10 Oct 2013 13:57:57 +0200 Subject: Stabilize tst_QComboBox::keyBoardNavigationWithMouse. The cursor needs to be within the view from start on Mac. Task-number: QTBUG-33973 Change-Id: I313c9fd1c3a917e135a92497f1818d1b0d8b7698 Reviewed-by: Gabriel de Dietrich --- .../auto/widgets/widgets/qcombobox/tst_qcombobox.cpp | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'tests/auto/widgets/widgets/qcombobox') diff --git a/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp b/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp index 4631154230..eabb7aaa17 100644 --- a/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp +++ b/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp @@ -2587,6 +2587,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; @@ -2597,6 +2609,7 @@ void tst_QComboBox::keyBoardNavigationWithMouse() combo.addItem( QString::number(i)); combo.show(); + 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(&combo)); @@ -2617,10 +2630,7 @@ void tst_QComboBox::keyBoardNavigationWithMouse() // When calling cursor function, Windows CE responds with: This function is not supported on this system. #ifndef Q_OS_WINCE // Force cursor movement to prevent QCursor::setPos() from returning prematurely on QPA: - const QPoint target(combo.view()->mapToGlobal(combo.view()->rect().center())); - QCursor::setPos(QPoint(target.x() + 1, target.y())); - QCursor::setPos(target); - + centerCursor(combo.view()); QTest::qWait(200); #define GET_SELECTION(SEL) \ @@ -2632,7 +2642,7 @@ void tst_QComboBox::keyBoardNavigationWithMouse() GET_SELECTION(selection); //since we moved the mouse is in the middle it should even be around 5; - QVERIFY(selection > 3); + QVERIFY2(selection > 3, (QByteArrayLiteral("selection=") + QByteArray::number(selection)).constData()); static const int final = 40; for (int i = selection + 1; i <= final; i++) -- cgit v1.2.3