QMenu auto-test: Add test for two-level tearable menus

This has been fixed in 5.6.1 but we can afford the extra test
to guard against regressions.

The setup for this test is two menus, one parent of the other.
The submenu is tearable. We open the parent menu, open its
submenu and then move the mouse cursor straight over the
submenu's tear-off area. The submenu should stay open even
after a short delay.

Change-Id: Ia8ad326d78dde31b6dd91b0ebacf0db1898715d4
Task-number: QTBUG-53068
Reviewed-by: Błażej Szczygieł <spaz16@wp.pl>
Reviewed-by: Gabriel de Dietrich <gabriel.dedietrich@qt.io>
This commit is contained in:
Gabriel de Dietrich 2016-04-29 15:58:46 -07:00 committed by Błażej Szczygieł
parent cdf1e67de1
commit 1acb29c3dd

View File

@ -90,6 +90,7 @@ private slots:
void mouseActivation(); void mouseActivation();
#endif #endif
void tearOff(); void tearOff();
void submenuTearOffDontClose();
void layoutDirection(); void layoutDirection();
void task208001_stylesheet(); void task208001_stylesheet();
@ -631,6 +632,51 @@ void tst_QMenu::tearOff()
QVERIFY(!torn->isVisible()); QVERIFY(!torn->isVisible());
} }
void tst_QMenu::submenuTearOffDontClose()
{
QWidget widget;
QMenu *menu = new QMenu(&widget);
QVERIFY(!menu->isTearOffEnabled()); //default value
menu->setTearOffEnabled(true);
QVERIFY(menu->isTearOffEnabled());
QMenu *submenu = new QMenu(&widget);
submenu->addAction("aaa");
submenu->addAction("bbb");
QVERIFY(!submenu->isTearOffEnabled()); //default value
submenu->setTearOffEnabled(true);
QVERIFY(submenu->isTearOffEnabled());
menu->addMenu(submenu);
widget.resize(300, 200);
centerOnScreen(&widget);
widget.show();
widget.activateWindow();
QVERIFY(QTest::qWaitForWindowActive(&widget));
// Show parent menu
menu->popup(widget.geometry().topRight() + QPoint(50, 0));
QVERIFY(QTest::qWaitForWindowActive(menu));
// Then its submenu
const QRect submenuRect = menu->actionGeometry(menu->actions().at(0));
const QPoint submenuPos(submenuRect.topLeft() + QPoint(3, 3));
// Move then click to avoid the submenu moves from causing it to close
QTest::mouseMove(menu, submenuPos, 100);
QTest::mouseClick(menu, Qt::LeftButton, 0, submenuPos, 100);
QTRY_VERIFY(QTest::qWaitForWindowActive(submenu));
// Make sure we enter the submenu frame directly on the tear-off area
QTest::mouseMove(submenu, QPoint(10, 3), 100);
if (submenu->style()->styleHint(QStyle::SH_Menu_SubMenuDontStartSloppyOnLeave)) {
qWarning("Sloppy menu timer disabled by the style: %s", qPrintable(QApplication::style()->objectName()));
// Submenu must get the enter event
QTRY_VERIFY(submenu->underMouse());
} else {
const int closeTimeout = submenu->style()->styleHint(QStyle::SH_Menu_SubMenuSloppyCloseTimeout);
QTest::qWait(closeTimeout + 100);
// Menu must not disappear and it must get the enter event
QVERIFY(submenu->isVisible());
QVERIFY(submenu->underMouse());
}
}
void tst_QMenu::layoutDirection() void tst_QMenu::layoutDirection()
{ {
QMainWindow win; QMainWindow win;