summaryrefslogtreecommitdiffstats
path: root/tests/auto/widgets/widgets/qmenu
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@theqtcompany.com>2016-02-24 14:47:20 +0000
committerThe Qt Project <gerrit-noreply@qt-project.org>2016-02-24 14:47:20 +0000
commitb736151c2bb6c68f700d38274d740a6e0cf59a49 (patch)
tree83e110a7205757addba6e86a3c2367e4b52afa05 /tests/auto/widgets/widgets/qmenu
parentff76300a5c9f209f625384f35ad0fdb0acebd799 (diff)
parent1fadc7292b66d4b3984bf5ef36c70b46b07a1c6b (diff)
Merge "Merge remote-tracking branch 'origin/5.6' into 5.7" into refs/staging/5.7
Diffstat (limited to 'tests/auto/widgets/widgets/qmenu')
-rw-r--r--tests/auto/widgets/widgets/qmenu/tst_qmenu.cpp109
1 files changed, 109 insertions, 0 deletions
diff --git a/tests/auto/widgets/widgets/qmenu/tst_qmenu.cpp b/tests/auto/widgets/widgets/qmenu/tst_qmenu.cpp
index 8ed781a023..17efc05f59 100644
--- a/tests/auto/widgets/widgets/qmenu/tst_qmenu.cpp
+++ b/tests/auto/widgets/widgets/qmenu/tst_qmenu.cpp
@@ -105,6 +105,9 @@ private slots:
void QTBUG7411_submenus_activate();
void QTBUG30595_rtl_submenu();
void QTBUG20403_nested_popup_on_shortcut_trigger();
+#ifndef QT_NO_CURSOR
+ void QTBUG47515_widgetActionEnterLeave();
+#endif
void QTBUG_10735_crashWithDialog();
#ifdef Q_OS_MAC
void QTBUG_37933_ampersands_data();
@@ -1066,6 +1069,112 @@ void tst_QMenu::QTBUG20403_nested_popup_on_shortcut_trigger()
QVERIFY(!subsub1.isVisible());
}
+class MyWidget : public QWidget
+{
+public:
+ MyWidget(QWidget *parent) :
+ QWidget(parent),
+ move(0), enter(0), leave(0)
+ {
+ setMinimumSize(100, 100);
+ setMouseTracking(true);
+ }
+
+ bool event(QEvent *e) Q_DECL_OVERRIDE
+ {
+ switch (e->type()) {
+ case QEvent::MouseMove:
+ ++move;
+ break;
+ case QEvent::Enter:
+ ++enter;
+ break;
+ case QEvent::Leave:
+ ++leave;
+ break;
+ default:
+ break;
+ }
+ return QWidget::event(e);
+ }
+
+ int move, enter, leave;
+};
+
+#ifndef QT_NO_CURSOR
+void tst_QMenu::QTBUG47515_widgetActionEnterLeave()
+{
+ if (QGuiApplication::platformName() == QLatin1String("cocoa"))
+ QSKIP("This test fails on OS X on CI");
+
+ const QPoint center = QGuiApplication::primaryScreen()->availableGeometry().center();
+ const QPoint cursorPos = center - QPoint(100, 100);
+
+ QScopedPointer<QMenu> menu1(new QMenu("Menu1"));
+ QScopedPointer<QMenu> menu2(new QMenu("Menu2"));
+
+ QWidgetAction *wA1 = new QWidgetAction(menu1.data());
+ MyWidget *w1 = new MyWidget(menu1.data());
+ wA1->setDefaultWidget(w1);
+
+ QWidgetAction *wA2 = new QWidgetAction(menu2.data());
+ MyWidget *w2 = new MyWidget(menu2.data());
+ wA2->setDefaultWidget(w2);
+
+ QAction *nextMenuAct = menu1->addMenu(menu2.data());
+
+ menu1->addAction(wA1);
+ menu2->addAction(wA2);
+
+ // Root menu
+ {
+ QCursor::setPos(cursorPos);
+ QCoreApplication::processEvents();
+
+ menu1->popup(center);
+ QVERIFY(QTest::qWaitForWindowExposed(menu1.data()));
+
+ QCursor::setPos(w1->mapToGlobal(w1->rect().center()));
+ QVERIFY(w1->isVisible());
+ QTRY_COMPARE(w1->leave, 0);
+ QTRY_COMPARE(w1->enter, 1);
+
+ // Check whether leave event is not delivered on mouse move
+ w1->move = 0;
+ QCursor::setPos(w1->mapToGlobal(w1->rect().center()) + QPoint(1, 1));
+ QTRY_COMPARE(w1->move, 1);
+ QTRY_COMPARE(w1->leave, 0);
+ QTRY_COMPARE(w1->enter, 1);
+
+ QCursor::setPos(cursorPos);
+ QTRY_COMPARE(w1->leave, 1);
+ QTRY_COMPARE(w1->enter, 1);
+ }
+
+ // Submenu
+ {
+ menu1->setActiveAction(nextMenuAct);
+ QVERIFY(QTest::qWaitForWindowExposed(menu2.data()));
+
+ QCursor::setPos(w2->mapToGlobal(w2->rect().center()));
+ QVERIFY(w2->isVisible());
+ QTRY_COMPARE(w2->leave, 0);
+ QTRY_COMPARE(w2->enter, 1);
+
+ // Check whether leave event is not delivered on mouse move
+ w2->move = 0;
+ QCursor::setPos(w2->mapToGlobal(w2->rect().center()) + QPoint(1, 1));
+ QTRY_COMPARE(w2->move, 1);
+ QTRY_COMPARE(w2->leave, 0);
+ QTRY_COMPARE(w2->enter, 1);
+
+ QCursor::setPos(cursorPos);
+ QTRY_COMPARE(w2->leave, 1);
+ QTRY_COMPARE(w2->enter, 1);
+ }
+}
+#endif // !QT_NO_CURSOR
+
class MyMenu : public QMenu
{
Q_OBJECT