diff options
author | J-P Nurmi <jpnurmi@qt.io> | 2017-06-10 10:18:21 +0200 |
---|---|---|
committer | J-P Nurmi <jpnurmi@qt.io> | 2017-06-12 09:25:54 +0000 |
commit | e81332e461ae7662b11fc1da04bb052e354514a3 (patch) | |
tree | d9fb9f8520fa3ebcca2cecdf9253a666784dd122 | |
parent | 027c24e6965b3fe1316c379c6de650bafd94dc08 (diff) |
Stabilize tst_menu
Add QQuickVisualTestUtil::moveMouseAway() (adapted from qtdeclarative)
to help with testing menus that are now highlighting items on hover.
It is important to move the mouse cursor away outside the window in
such tests where hover highlight might conflict with the test.
Change-Id: If3d642dd4f3ba2936a0d22c078d8fb0125d16c6c
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
-rw-r--r-- | tests/auto/menu/tst_menu.cpp | 6 | ||||
-rw-r--r-- | tests/auto/shared/visualtestutil.cpp | 9 | ||||
-rw-r--r-- | tests/auto/shared/visualtestutil.h | 2 |
3 files changed, 17 insertions, 0 deletions
diff --git a/tests/auto/menu/tst_menu.cpp b/tests/auto/menu/tst_menu.cpp index f788d5ee..7e892025 100644 --- a/tests/auto/menu/tst_menu.cpp +++ b/tests/auto/menu/tst_menu.cpp @@ -91,6 +91,7 @@ void tst_menu::mouse() QQuickApplicationWindow *window = helper.appWindow; window->show(); QVERIFY(QTest::qWaitForWindowActive(window)); + moveMouseAway(window); QQuickMenu *menu = window->property("menu").value<QQuickMenu*>(); menu->open(); @@ -180,6 +181,7 @@ void tst_menu::contextMenuKeyboard() window->requestActivate(); QVERIFY(QTest::qWaitForWindowActive(window)); QVERIFY(QGuiApplication::focusWindow() == window); + moveMouseAway(window); QQuickMenu *menu = window->property("menu").value<QQuickMenu*>(); QCOMPARE(menu->contentItem()->property("currentIndex"), QVariant(-1)); @@ -439,6 +441,7 @@ void tst_menu::popup() QVERIFY(menuItem3); #if QT_CONFIG(cursor) + QPoint oldCursorPos = QCursor::pos(); QPoint cursorPos = window->mapToGlobal(QPoint(11, 22)); QCursor::setPos(cursorPos); QTRY_COMPARE(QCursor::pos(), cursorPos); @@ -485,6 +488,9 @@ void tst_menu::popup() QTRY_COMPARE(menu->property("y").toInt(), window->height() / 3 * 2 + menu->topPadding() - menuItem->y()); menu->close(); } + + QCursor::setPos(oldCursorPos); + QTRY_COMPARE(QCursor::pos(), oldCursorPos); #endif } diff --git a/tests/auto/shared/visualtestutil.cpp b/tests/auto/shared/visualtestutil.cpp index 60b8790d..5e44f5e7 100644 --- a/tests/auto/shared/visualtestutil.cpp +++ b/tests/auto/shared/visualtestutil.cpp @@ -38,6 +38,7 @@ #include <QtQuick/QQuickItem> #include <QtCore/QDebug> +#include <QtGui/QCursor> bool QQuickVisualTestUtil::delegateVisible(QQuickItem *item) { @@ -69,3 +70,11 @@ void QQuickVisualTestUtil::dumpTree(QQuickItem *parent, int depth) } } +void QQuickVisualTestUtil::moveMouseAway(QQuickWindow *window) +{ +#if QT_CONFIG(cursor) // Get the cursor out of the way. + QCursor::setPos(window->geometry().topRight() + QPoint(100, 100)); +#else + Q_UNUSED(window) +#endif +} diff --git a/tests/auto/shared/visualtestutil.h b/tests/auto/shared/visualtestutil.h index 12f955ea..bcf45660 100644 --- a/tests/auto/shared/visualtestutil.h +++ b/tests/auto/shared/visualtestutil.h @@ -54,6 +54,8 @@ namespace QQuickVisualTestUtil bool delegateVisible(QQuickItem *item); + void moveMouseAway(QQuickWindow *window); + /* Find an item with the specified objectName. If index is supplied then the item must also evaluate the {index} expression equal to index |