summaryrefslogtreecommitdiffstats
path: root/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp')
-rw-r--r--tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp61
1 files changed, 51 insertions, 10 deletions
diff --git a/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp b/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp
index f19d7619cc..f8dc5d91a2 100644
--- a/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp
+++ b/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp
@@ -119,6 +119,7 @@ private slots:
#if !defined(Q_OS_DARWIN)
void check_shortcutPress();
void check_menuPosition();
+ void taskQTBUG46812_doNotLeaveMenubarHighlighted();
#endif
void task223138_triggered();
void task256322_highlight();
@@ -230,9 +231,14 @@ TestMenu tst_QMenuBar::initSimpleMenuBar(QMenuBar *mb, bool forceNonNative) {
menu = mb->addMenu(QStringLiteral("accel1"));
action = menu->addAction(QStringLiteral("&Open...") );
action->setShortcut(Qt::Key_O);
+ result.actions << action;
+
+ action = menu->addAction(QStringLiteral("action"));
+ action->setShortcut(QKeySequence(Qt::ALT + Qt::Key_Z));
+ result.actions << action;
+
result.menus << menu;
connect(menu, SIGNAL(triggered(QAction*)), this, SLOT(onSimpleActivated(QAction*)));
- result.actions << action;
m_lastSimpleAcceleratorId = 0;
m_simpleActivatedCount = 0;
@@ -318,7 +324,7 @@ inline TestMenu tst_QMenuBar::initWindowWithComplexMenuBar(QMainWindow &w)
return initComplexMenuBar(w.menuBar());
}
-// On Mac/WinCE, native key events are needed to test menu action activation
+// On Mac native key events are needed to test menu action activation
#if !defined(Q_OS_DARWIN)
void tst_QMenuBar::accel()
{
@@ -336,7 +342,7 @@ void tst_QMenuBar::accel()
}
#endif
-// On Mac/WinCE, native key events are needed to test menu action activation
+// On Mac native key events are needed to test menu action activation
#if !defined(Q_OS_DARWIN)
void tst_QMenuBar::activatedCount()
{
@@ -535,7 +541,7 @@ void tst_QMenuBar::insertItem_QString_QObject()
QVERIFY(actions.size() < 4); // there is no menu 4!
}
-// On Mac/WinCE, native key events are needed to test menu action activation
+// On Mac native key events are needed to test menu action activation
#if !defined(Q_OS_DARWIN)
void tst_QMenuBar::check_accelKeys()
{
@@ -608,7 +614,7 @@ void tst_QMenuBar::check_accelKeys()
}
#endif
-// On Mac/WinCE, native key events are needed to test menu action activation
+// On Mac native key events are needed to test menu action activation
#if !defined(Q_OS_DARWIN)
void tst_QMenuBar::check_cursorKeys1()
{
@@ -642,7 +648,7 @@ void tst_QMenuBar::check_cursorKeys1()
}
#endif
-// Qt/Mac,WinCE does not use the native popups/menubar
+// Qt/Mac does not use the native popups/menubar
#if !defined(Q_OS_DARWIN)
void tst_QMenuBar::check_cursorKeys2()
{
@@ -675,7 +681,7 @@ void tst_QMenuBar::check_cursorKeys2()
/*!
If a popupmenu is active you can use Left to move to the menu to the left of it.
*/
-// Qt/Mac,WinCE does not use the native popups/menubar
+// Qt/Mac does not use the native popups/menubar
#if !defined(Q_OS_DARWIN)
void tst_QMenuBar::check_cursorKeys3()
{
@@ -790,7 +796,7 @@ void tst_QMenuBar::check_endKey()
If Down is pressed next the popup is activated again.
*/
-// Qt/Mac,WinCE does not use the native popups/menubar
+// Qt/Mac does not use the native popups/menubar
#if !defined(Q_OS_DARWIN)
void tst_QMenuBar::check_escKey()
{
@@ -1024,7 +1030,7 @@ void tst_QMenuBar::check_altClosePress()
QTRY_VERIFY(!w.menuBar()->activeAction());
}
-// Qt/Mac,WinCE does not use the native popups/menubar
+// Qt/Mac does not use the native popups/menubar
#if !defined(Q_OS_DARWIN)
void tst_QMenuBar::check_shortcutPress()
{
@@ -1067,7 +1073,7 @@ private:
const Qt::LayoutDirection m_oldDirection;
};
-// Qt/Mac,WinCE does not use the native popups/menubar
+// Qt/Mac does not use the native popups/menubar
#if !defined(Q_OS_DARWIN)
void tst_QMenuBar::check_menuPosition()
{
@@ -1529,6 +1535,41 @@ void tst_QMenuBar::slotForTaskQTBUG53205()
taskQTBUG53205MenuBar->setParent(parent);
}
+// Qt/Mac does not use the native popups/menubar
+#if !defined(Q_OS_DARWIN)
+void tst_QMenuBar::taskQTBUG46812_doNotLeaveMenubarHighlighted()
+{
+ QMainWindow mainWindow;
+ QWidget *centralWidget = new QWidget;
+ centralWidget->setFocusPolicy(Qt::StrongFocus);
+ mainWindow.setCentralWidget(centralWidget);
+ initWindowWithSimpleMenuBar(mainWindow);
+
+ mainWindow.show();
+ QApplication::setActiveWindow(&mainWindow);
+ QVERIFY(QTest::qWaitForWindowActive(&mainWindow));
+
+ QVERIFY(!mainWindow.menuBar()->hasFocus());
+ QCOMPARE(m_simpleActivatedCount, 0);
+
+ QTest::keyPress(&mainWindow, Qt::Key_Alt, Qt::AltModifier);
+ QVERIFY(!mainWindow.menuBar()->hasFocus());
+ QCOMPARE(m_simpleActivatedCount, 0);
+
+ QTest::keyPress(&mainWindow, Qt::Key_Z, Qt::AltModifier);
+ QVERIFY(!mainWindow.menuBar()->hasFocus());
+ QCOMPARE(m_simpleActivatedCount, 2); // the action AND the menu will activate
+
+ QTest::keyRelease(&mainWindow, Qt::Key_Alt, Qt::NoModifier);
+ QVERIFY(!mainWindow.menuBar()->hasFocus());
+ QCOMPARE(m_simpleActivatedCount, 2);
+
+ QTest::keyRelease(&mainWindow, Qt::Key_Z, Qt::NoModifier);
+ QVERIFY(!mainWindow.menuBar()->hasFocus());
+ QCOMPARE(m_simpleActivatedCount, 2);
+}
+#endif
+
#ifdef Q_OS_MACOS
extern bool tst_qmenubar_taskQTBUG56275(QMenuBar *);