diff options
Diffstat (limited to 'tests/auto/widgets/widgets/qmenubar')
-rw-r--r-- | tests/auto/widgets/widgets/qmenubar/BLACKLIST | 10 | ||||
-rw-r--r-- | tests/auto/widgets/widgets/qmenubar/CMakeLists.txt | 18 | ||||
-rw-r--r-- | tests/auto/widgets/widgets/qmenubar/qmenubar.pro | 9 | ||||
-rw-r--r-- | tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp | 393 | ||||
-rw-r--r-- | tests/auto/widgets/widgets/qmenubar/tst_qmenubar_mac.mm | 29 |
5 files changed, 148 insertions, 311 deletions
diff --git a/tests/auto/widgets/widgets/qmenubar/BLACKLIST b/tests/auto/widgets/widgets/qmenubar/BLACKLIST index d412fe6e81..516fd39f86 100644 --- a/tests/auto/widgets/widgets/qmenubar/BLACKLIST +++ b/tests/auto/widgets/widgets/qmenubar/BLACKLIST @@ -1,7 +1,5 @@ [check_menuPosition] -ubuntu-16.04 -#QTBUG-66255 -ubuntu-18.04 -ubuntu-20.04 -[activatedCount] -opensuse-42.3 +ubuntu-22.04 +# QTBUG-87421 +[cornerWidgets] +android diff --git a/tests/auto/widgets/widgets/qmenubar/CMakeLists.txt b/tests/auto/widgets/widgets/qmenubar/CMakeLists.txt index 1b412981d8..f2b1c1bec6 100644 --- a/tests/auto/widgets/widgets/qmenubar/CMakeLists.txt +++ b/tests/auto/widgets/widgets/qmenubar/CMakeLists.txt @@ -1,24 +1,32 @@ -# Generated from qmenubar.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qmenubar Test: ##################################################################### -qt_add_test(tst_qmenubar +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qmenubar LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + +qt_internal_add_test(tst_qmenubar SOURCES tst_qmenubar.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::Gui Qt::TestPrivate Qt::Widgets + Qt::WidgetsPrivate ) ## Scopes: ##################################################################### -qt_extend_target(tst_qmenubar CONDITION MACOS +qt_internal_extend_target(tst_qmenubar CONDITION MACOS SOURCES tst_qmenubar_mac.mm - PUBLIC_LIBRARIES + LIBRARIES ${FWAppKit} ) diff --git a/tests/auto/widgets/widgets/qmenubar/qmenubar.pro b/tests/auto/widgets/widgets/qmenubar/qmenubar.pro deleted file mode 100644 index bde0026517..0000000000 --- a/tests/auto/widgets/widgets/qmenubar/qmenubar.pro +++ /dev/null @@ -1,9 +0,0 @@ -CONFIG += testcase -TARGET = tst_qmenubar -QT += widgets testlib testlib-private -SOURCES += tst_qmenubar.cpp - -macos: { - OBJECTIVE_SOURCES += tst_qmenubar_mac.mm - LIBS += -framework AppKit -} diff --git a/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp b/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp index 7a9676f56b..06750b099b 100644 --- a/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp +++ b/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp @@ -1,33 +1,9 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - - -#include <QtTest/QtTest> +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + + +#include <QTest> +#include <QSignalSpy> #include <qapplication.h> #include <qmainwindow.h> #include <qmenubar.h> @@ -39,10 +15,13 @@ #include <QVBoxLayout> #include <QLabel> #include <QPlainTextEdit> +#include <QTranslator> #include <qscreen.h> #include <qobject.h> +#include <QtWidgets/private/qapplication_p.h> + QT_FORWARD_DECLARE_CLASS(QMainWindow) #include <qmenubar.h> @@ -114,13 +93,6 @@ private slots: #endif void allowActiveAndDisabled(); void taskQTBUG56860_focus(); - void check_endKey(); - void check_homeKey(); - -// void check_mouse1_data(); -// void check_mouse1(); -// void check_mouse2_data(); -// void check_mouse2(); void check_altPress(); void check_altClosePress(); @@ -143,6 +115,8 @@ private slots: #ifdef Q_OS_MACOS void taskQTBUG56275_reinsertMenuInParentlessQMenuBar(); void QTBUG_57404_existingMenuItemException(); + void defaultEditMenuItems(); + #endif void QTBUG_25669_menubarActionDoubleTriggered(); void taskQTBUG55966_subMenuRemoved(); @@ -150,6 +124,9 @@ private slots: void platformMenu(); void addActionQt5connect(); void QTBUG_65488_hiddenActionTriggered(); + void pressDragRelease_data(); + void pressDragRelease(); + protected slots: void onSimpleActivated( QAction*); void onComplexActionTriggered(); @@ -167,6 +144,7 @@ private: int m_simpleActivatedCount; int m_complexTriggerCount[int('k')]; QMenuBar* taskQTBUG53205MenuBar; + QScopedPointer<QPointingDevice> m_touchScreen = QScopedPointer<QPointingDevice>(QTest::createTouchDevice()); }; // Testing get/set functions @@ -233,8 +211,8 @@ TestMenu tst_QMenuBar::initSimpleMenuBar(QMenuBar *mb, bool forceNonNative) { QMenu *menu = mb->addMenu(QStringLiteral("&accel")); QAction *action = menu->addAction(QStringLiteral("menu1") ); #if QT_CONFIG(shortcut) - action->setShortcut(QKeySequence(Qt::ALT + Qt::Key_A)); - action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_A)); + action->setShortcut(QKeySequence(Qt::ALT | Qt::Key_A)); + action->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_A)); #endif connect(menu, SIGNAL(triggered(QAction*)), this, SLOT(onSimpleActivated(QAction*))); result.menus << menu; @@ -249,7 +227,7 @@ TestMenu tst_QMenuBar::initSimpleMenuBar(QMenuBar *mb, bool forceNonNative) { action = menu->addAction(QStringLiteral("action")); #if QT_CONFIG(shortcut) - action->setShortcut(QKeySequence(Qt::ALT + Qt::Key_Z)); + action->setShortcut(QKeySequence(Qt::ALT | Qt::Key_Z)); #endif result.actions << action; @@ -290,7 +268,7 @@ QAction *tst_QMenuBar::createCharacterAction(QMenu *menu, char lowerAscii) action->setObjectName(text); action->setData(QVariant(int(lowerAscii))); #if QT_CONFIG(shortcut) - action->setShortcut(Qt::CTRL + Qt::Key(lowerAscii - 'a' + int(Qt::Key_A))); + action->setShortcut(Qt::CTRL | Qt::Key(lowerAscii - 'a' + int(Qt::Key_A))); #endif connect(action, SIGNAL(triggered()), this, SLOT(onComplexActionTriggered())); return action; @@ -327,7 +305,7 @@ TestMenu tst_QMenuBar::initComplexMenuBar(QMenuBar *mb) QAction *action = mb->addAction(QStringLiteral("M&enu 3")); action->setData(QVariant(3)); #if QT_CONFIG(shortcut) - action->setShortcut(Qt::ALT + Qt::Key_J); + action->setShortcut(Qt::ALT | Qt::Key_J); #endif connect(action, SIGNAL(triggered()), this, SLOT(onComplexActionTriggered())); result.actions << action; @@ -355,7 +333,6 @@ void tst_QMenuBar::accel() QMainWindow w; const TestMenu menu = initWindowWithSimpleMenuBar(w); w.show(); - QApplication::setActiveWindow(&w); QVERIFY(QTest::qWaitForWindowActive(&w)); // shortcuts won't work unless the window is active QTest::keyClick(static_cast<QWidget *>(0), Qt::Key_A, Qt::ControlModifier ); @@ -377,7 +354,6 @@ void tst_QMenuBar::activatedCount() QFETCH( bool, forceNonNative ); initWindowWithSimpleMenuBar(w, forceNonNative); w.show(); - QApplication::setActiveWindow(&w); QVERIFY(QTest::qWaitForWindowActive(&w)); QTest::keyClick(static_cast<QWidget *>(0), Qt::Key_A, Qt::ControlModifier ); @@ -577,7 +553,6 @@ void tst_QMenuBar::check_accelKeys() QMainWindow w; initWindowWithComplexMenuBar(w); w.show(); - QApplication::setActiveWindow(&w); QVERIFY(QTest::qWaitForWindowActive(&w)); // start with a bogus key that shouldn't trigger anything @@ -656,7 +631,6 @@ void tst_QMenuBar::check_cursorKeys1() QMainWindow w; initWindowWithComplexMenuBar(w); w.show(); - QApplication::setActiveWindow(&w); QVERIFY(QTest::qWaitForWindowActive(&w)); // start with a ALT + 1 that activates the first popupmenu @@ -696,7 +670,6 @@ void tst_QMenuBar::check_cursorKeys2() QMainWindow w; initWindowWithComplexMenuBar(w); w.show(); - QApplication::setActiveWindow(&w); QVERIFY(QTest::qWaitForWindowActive(&w)); // select popupmenu2 @@ -735,7 +708,6 @@ void tst_QMenuBar::check_cursorKeys3() QMainWindow w; initWindowWithComplexMenuBar(w); w.show(); - QApplication::setActiveWindow(&w); QVERIFY(QTest::qWaitForWindowActive(&w)); // select Popupmenu 2 @@ -777,7 +749,6 @@ void tst_QMenuBar::taskQTBUG56860_focus() w.setCentralWidget(e); w.show(); - QApplication::setActiveWindow(&w); QVERIFY(QTest::qWaitForWindowActive(&w)); QTRY_COMPARE(QApplication::focusWidget(), e); @@ -804,85 +775,6 @@ void tst_QMenuBar::taskQTBUG56860_focus() } /*! - If a popupmenu is active you can use home to go quickly to the first item in the menu. -*/ -void tst_QMenuBar::check_homeKey() -{ - // I'm temporarily shutting up this testcase. - // Seems like the behaviour i'm expecting isn't ok. - QSKIP("This test has been \"temporarily\" disabled at least since 2009 :)"); - - QEXPECT_FAIL( "0", "Popupmenu should respond to a Home key", Abort ); - - QMainWindow w; - initWindowWithComplexMenuBar(w); - w.show(); - QApplication::setActiveWindow(&w); - QVERIFY(QTest::qWaitForWindowActive(&w)); - - // select Popupmenu 2 - QTest::keyClick(static_cast<QWidget *>(0), Qt::Key_2, Qt::AltModifier ); - - // Simulate some keys - QTest::keyClick(static_cast<QWidget *>(0), Qt::Key_Down ); - QTest::keyClick(static_cast<QWidget *>(0), Qt::Key_Down ); - QTest::keyClick(static_cast<QWidget *>(0), Qt::Key_Down ); - QTest::keyClick(static_cast<QWidget *>(0), Qt::Key_Home ); - // and press ENTER - QTest::keyClick(static_cast<QWidget *>(0), Qt::Key_Enter ); - // Let's see if the correct slot is called... -// QVERIFY2( m_complexActionTriggerCount[int('c')] == 1, "Popupmenu should respond to a Home key" ); - QCOMPARE(m_complexTriggerCount[int('c')], 1); - QCOMPARE(m_complexTriggerCount[3], 0); - QCOMPARE(m_complexTriggerCount[4], 0); - QCOMPARE(m_complexTriggerCount[int('a')], 0); - QCOMPARE(m_complexTriggerCount[int('b')], 0); - QCOMPARE(m_complexTriggerCount[int('d')], 0); - QCOMPARE(m_complexTriggerCount[int('e')], 0); - QCOMPARE(m_complexTriggerCount[int('f')], 0); - QCOMPARE(m_complexTriggerCount[int('g')], 0); - QCOMPARE(m_complexTriggerCount[int('h')], 0); -} - -/*! - If a popupmenu is active you can use end to go quickly to the last item in the menu. -*/ -void tst_QMenuBar::check_endKey() -{ - // I'm temporarily silenting this testcase. - // Seems like the behaviour i'm expecting isn't ok. - QSKIP("This test has been \"temporarily\" disabled at least since 2009 :)"); - - QEXPECT_FAIL( "0", "Popupmenu should respond to an End key", Abort ); - - QMainWindow w; - initWindowWithComplexMenuBar(w); - w.show(); - QApplication::setActiveWindow(&w); - QVERIFY(QTest::qWaitForWindowActive(&w)); - - // select Popupmenu 2 - QTest::keyClick(static_cast<QWidget *>(0), Qt::Key_2, Qt::AltModifier ); - - // Simulate some keys - QTest::keyClick(static_cast<QWidget *>(0), Qt::Key_End ); - // and press ENTER - QTest::keyClick(static_cast<QWidget *>(0), Qt::Key_Enter ); - // Let's see if the correct slot is called... -// QVERIFY2( m_complexActionTriggerCount[int('h')] == 1, "Popupmenu should respond to an End key" ); - QCOMPARE(m_complexTriggerCount[int('h')], 1);//, "Popupmenu should respond to an End key"); - QCOMPARE(m_complexTriggerCount[3], 0); - QCOMPARE(m_complexTriggerCount[4], 0); - QCOMPARE(m_complexTriggerCount[int('a')], 0); - QCOMPARE(m_complexTriggerCount[int('b')], 0); - QCOMPARE(m_complexTriggerCount[int('c')], 0); - QCOMPARE(m_complexTriggerCount[int('d')], 0); - QCOMPARE(m_complexTriggerCount[int('e')], 0); - QCOMPARE(m_complexTriggerCount[int('f')], 0); - QCOMPARE(m_complexTriggerCount[int('g')], 0); -} - -/*! If a popupmenu is active you can use esc to hide the menu and then the menubar should become active. If Down is pressed next the popup is activated again. @@ -899,7 +791,6 @@ void tst_QMenuBar::check_escKey() const TestMenu menu = initWindowWithComplexMenuBar(w); w.show(); w.setFocus(); - QApplication::setActiveWindow(&w); QVERIFY(QTest::qWaitForWindowActive(&w)); QVERIFY( !menu.menus.at(0)->isActiveWindow() ); @@ -920,7 +811,7 @@ void tst_QMenuBar::check_escKey() if (!QGuiApplication::platformName().compare(QLatin1String("minimal"), Qt::CaseInsensitive) || !QGuiApplication::platformName().compare(QLatin1String("offscreen"), Qt::CaseInsensitive)) { - QWARN("Skipping menu button test on minimal/offscreen platforms"); + qWarning("Skipping menu button test on minimal/offscreen platforms"); return; } @@ -937,112 +828,6 @@ void tst_QMenuBar::check_escKey() #endif -// void tst_QMenuBar::check_mouse1_data() -// { -// QTest::addColumn<QString>("popup_item"); -// QTest::addColumn<int>("itemA_count"); -// QTest::addColumn<int>("itemB_count"); - -// QTest::newRow( "A" ) << QString( "Item A Ctrl+A" ) << 1 << 0; -// QTest::newRow( "B" ) << QString( "Item B Ctrl+B" ) << 0 << 1; -// } - -// /*! -// Check if the correct signals are emitted if we select a popupmenu. -// */ -// void tst_QMenuBar::check_mouse1() -// { -// if (QSystem::curStyle() == "Motif") -// QSKIP("This fails in Motif due to a bug in the testing framework"); -// QFETCH( QString, popup_item ); -// QFETCH( int, itemA_count ); -// QFETCH( int, itemB_count ); - -// // initComplexMenubar(); -// QVERIFY( !pm1->isActiveWindow() ); -// QVERIFY( !pm2->isActiveWindow() ); - -// QTest::qWait(1000); -// QtTestMouse mouse; -// mouse.mouseEvent( QtTestMouse::MouseClick, mb, "Menu &1", Qt::LeftButton ); - -// QVERIFY( pm1->isActiveWindow() ); -// QVERIFY( !pm2->isActiveWindow() ); - -// QTest::qWait(1000); -// mouse.mouseEvent( QtTestMouse::MouseClick, pm1, popup_item, Qt::LeftButton ); - -// QCOMPARE(m_complexActionTriggerCount[3], 0); -// QCOMPARE(m_complexActionTriggerCount[4], 0); -// QCOMPARE(m_complexActionTriggerCount['a'], (uint)itemA_count); // this option should have fired -// QCOMPARE(m_complexActionTriggerCount['b'], (uint)itemB_count); -// QCOMPARE(m_complexActionTriggerCount['c'], 0); -// QCOMPARE(m_complexActionTriggerCount['d'], 0); -// QCOMPARE(m_complexActionTriggerCount['e'], 0); -// QCOMPARE(m_complexActionTriggerCount['f'], 0); -// QCOMPARE(m_complexActionTriggerCount['g'], 0); -// } - -// void tst_QMenuBar::check_mouse2_data() -// { -// QTest::addColumn<QString>("label"); -// QTest::addColumn<int>("itemA_count"); -// QTest::addColumn<int>("itemB_count"); -// QTest::addColumn<int>("itemC_count"); -// QTest::addColumn<int>("itemD_count"); -// QTest::addColumn<int>("itemE_count"); -// QTest::addColumn<int>("itemF_count"); -// QTest::addColumn<int>("itemG_count"); -// QTest::addColumn<int>("itemH_count"); -// QTest::addColumn<int>("menu3_count"); - -// QTest::newRow( "A" ) << QString( "Menu &1/Item A Ctrl+A" ) << 1 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0; -// QTest::newRow( "B" ) << QString( "Menu &1/Item B Ctrl+B" ) << 0 << 1 << 0 << 0 << 0 << 0 << 0 << 0 << 0; -// QTest::newRow( "C" ) << QString( "Menu &2/Item C Ctrl+C" ) << 0 << 0 << 1 << 0 << 0 << 0 << 0 << 0 << 0; -// QTest::newRow( "D" ) << QString( "Menu &2/Item D Ctrl+D" ) << 0 << 0 << 0 << 1 << 0 << 0 << 0 << 0 << 0; -// QTest::newRow( "E" ) << QString( "Menu &2/Item E Ctrl+E" ) << 0 << 0 << 0 << 0 << 1 << 0 << 0 << 0 << 0; -// QTest::newRow( "F" ) << QString( "Menu &2/Item F Ctrl+F" ) << 0 << 0 << 0 << 0 << 0 << 1 << 0 << 0 << 0; -// QTest::newRow( "G" ) << QString( "Menu &2/Item G Ctrl+G" ) << 0 << 0 << 0 << 0 << 0 << 0 << 1 << 0 << 0; -// QTest::newRow( "H" ) << QString( "Menu &2/Item H Ctrl+H" ) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 1 << 0; -// QTest::newRow( "menu 3" ) << QString( "M&enu 3" ) << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 1; -// } - -// /*! -// Check if the correct signals are emitted if we select a popupmenu. -// This time, we use a little bit more magic from the testframework. -// */ -// void tst_QMenuBar::check_mouse2() -// { -// if (QSystem::curStyle() == "Motif") -// QSKIP("This fails in Motif due to a bug in the testing framework"); -// QFETCH( QString, label ); -// QFETCH( int, itemA_count ); -// QFETCH( int, itemB_count ); -// QFETCH( int, itemC_count ); -// QFETCH( int, itemD_count ); -// QFETCH( int, itemE_count ); -// QFETCH( int, itemF_count ); -// QFETCH( int, itemG_count ); -// QFETCH( int, itemH_count ); -// QFETCH( int, menu3_count ); - -// // initComplexMenubar(); -// QtTestMouse mouse; -// mouse.click( QtTestMouse::Menu, label, Qt::LeftButton ); - -// // check if the correct signals have fired -// QCOMPARE(m_complexActionTriggerCount[3], (uint)menu3_count); -// QCOMPARE(m_complexActionTriggerCount[4], 0); -// QCOMPARE(m_complexActionTriggerCount['a'], (uint)itemA_count); -// QCOMPARE(m_complexActionTriggerCount['b'], (uint)itemB_count); -// QCOMPARE(m_complexActionTriggerCount['c'], (uint)itemC_count); -// QCOMPARE(m_complexActionTriggerCount['d'], (uint)itemD_count); -// QCOMPARE(m_complexActionTriggerCount['e'], (uint)itemE_count); -// QCOMPARE(m_complexActionTriggerCount['f'], (uint)itemF_count); -// QCOMPARE(m_complexActionTriggerCount['g'], (uint)itemG_count); -// QCOMPARE(m_complexActionTriggerCount['h'], (uint)itemH_count); -// } - void tst_QMenuBar::allowActiveAndDisabled() { QMenuBar menuBar; @@ -1097,7 +882,6 @@ void tst_QMenuBar::check_altPress() initWindowWithSimpleMenuBar(w); w.show(); w.setFocus(); - QApplication::setActiveWindow(&w); QVERIFY(QTest::qWaitForWindowActive(&w)); QTest::keyClick( &w, Qt::Key_Alt ); @@ -1127,7 +911,6 @@ void tst_QMenuBar::check_altClosePress() w.show(); w.move(QGuiApplication::primaryScreen()->availableGeometry().center()); - QApplication::setActiveWindow(&w); QVERIFY(QTest::qWaitForWindowActive(&w)); QTest::keyClick(&w, Qt::Key_F, Qt::AltModifier); @@ -1148,7 +931,6 @@ void tst_QMenuBar::check_shortcutPress() const TestMenu menu = initWindowWithComplexMenuBar(w); w.show(); w.setFocus(); - QApplication::setActiveWindow(&w); QVERIFY(QTest::qWaitForWindowActive(&w)); QCOMPARE(m_complexTriggerCount[3], 0); @@ -1205,7 +987,6 @@ void tst_QMenuBar::check_menuPosition() QAction *menu_action = w.menuBar()->addMenu(&menu); centerOnScreen(&w); w.show(); - qApp->setActiveWindow(&w); QVERIFY(QTest::qWaitForWindowActive(&w)); //the menu should be below the menubar item @@ -1289,9 +1070,9 @@ void tst_QMenuBar::task223138_triggered() //let's trigger the first action top->trigger(); - QCOMPARE(menubarSpy.count(), 1); - QCOMPARE(menuSpy.count(), 1); - QCOMPARE(submenuSpy.count(), 0); + QCOMPARE(menubarSpy.size(), 1); + QCOMPARE(menuSpy.size(), 1); + QCOMPARE(submenuSpy.size(), 0); menubarSpy.clear(); menuSpy.clear(); @@ -1299,9 +1080,9 @@ void tst_QMenuBar::task223138_triggered() //let's trigger the sub action action->trigger(); - QCOMPARE(menubarSpy.count(), 1); - QCOMPARE(menuSpy.count(), 1); - QCOMPARE(submenuSpy.count(), 1); + QCOMPARE(menubarSpy.size(), 1); + QCOMPARE(menuSpy.size(), 1); + QCOMPARE(submenuSpy.size(), 1); } void tst_QMenuBar::task256322_highlight() @@ -1324,7 +1105,6 @@ void tst_QMenuBar::task256322_highlight() centerOnScreen(&win); win.show(); - QApplication::setActiveWindow(&win); QVERIFY(QTest::qWaitForWindowActive(&win)); const QPoint filePos = menuBarActionWindowPos(win.menuBar(), file); @@ -1355,7 +1135,8 @@ void tst_QMenuBar::menubarSizeHint() { MyStyle() : QProxyStyle(QStyleFactory::create("windows")) { } - virtual int pixelMetric(PixelMetric metric, const QStyleOption * option = 0, const QWidget * widget = 0 ) const + int pixelMetric(PixelMetric metric, const QStyleOption *option = 0, + const QWidget *widget = 0) const override { // I chose strange values (prime numbers to be more sure that the size of the menubar is correct) switch (metric) @@ -1379,8 +1160,8 @@ void tst_QMenuBar::menubarSizeHint() mb.setStyle(&style); //this is a list of arbitrary strings so that we check the geometry - QStringList list = QStringList() << "trer" << "ezrfgtgvqd" << "sdgzgzerzerzer" << "eerzertz" << "er"; - foreach(QString str, list) + const auto list = QStringList{"trer", "ezrfgtgvqd", "sdgzgzerzerzer", "eerzertz", "er"}; + for (const QString &str : list) mb.addAction(str); const int panelWidth = style.pixelMetric(QStyle::PM_MenuBarPanelWidth); @@ -1391,7 +1172,8 @@ void tst_QMenuBar::menubarSizeHint() centerOnScreen(&mb); mb.show(); QRect result; - foreach(QAction *action, mb.actions()) { + const auto actions = mb.actions(); + for (QAction *action : actions) { const QRect actionRect = mb.actionGeometry(action); if (!result.isNull()) //this is the first item QCOMPARE(actionRect.left() - result.right() - 1, spacing); @@ -1427,11 +1209,11 @@ void tst_QMenuBar::taskQTBUG4965_escapeEaten() QMenu menu("menu1"); QAction *first = menubar.addMenu(&menu); #if QT_CONFIG(shortcut) - menu.addAction("quit", &menubar, SLOT(close()), QKeySequence("ESC")); + menu.addAction("quit", QKeySequence("ESC"), &menubar, SLOT(close())); #endif centerOnScreen(&menubar); menubar.show(); - QApplication::setActiveWindow(&menubar); + QApplicationPrivate::setActiveWindow(&menubar); QVERIFY(QTest::qWaitForWindowExposed(&menubar)); menubar.setActiveAction(first); QTRY_VERIFY(menu.isVisible()); @@ -1462,7 +1244,6 @@ void tst_QMenuBar::taskQTBUG11823_crashwithInvisibleActions() centerOnScreen(&menubar); menubar.show(); - QApplication::setActiveWindow(&menubar); QVERIFY(QTest::qWaitForWindowActive(&menubar)); menubar.setActiveAction(m); QCOMPARE(menubar.activeAction(), m); @@ -1493,7 +1274,6 @@ void tst_QMenuBar::closeOnSecondClickAndOpenOnThirdClick() // QTBUG-32807, menu QMenu *fileMenu = menuBar->addMenu(QStringLiteral("OpenCloseOpen")); fileMenu->addAction(QStringLiteral("Quit")); mainWindow.show(); - QApplication::setActiveWindow(&mainWindow); QVERIFY(QTest::qWaitForWindowActive(&mainWindow)); const QPoint center = menuBarActionWindowPos(mainWindow.menuBar(), fileMenu->menuAction()); @@ -1588,7 +1368,6 @@ void tst_QMenuBar::taskQTBUG53205_crashReparentNested() mainWindow.resize(300, 200); centerOnScreen(&mainWindow); const TestMenu testMenus = initWindowWithComplexMenuBar(mainWindow); - QApplication::setActiveWindow(&mainWindow); // they can't be windows QWidget hiddenParent(&mainWindow, {}); @@ -1638,12 +1417,75 @@ void tst_QMenuBar::QTBUG_65488_hiddenActionTriggered() // resize to action's size to make Action1 hidden win.resize(actRect.width() - 10, win.size().height()); win.show(); - QApplication::setActiveWindow(&win); QVERIFY(QTest::qWaitForWindowExposed(&win)); // click center of the blank area on the menubar where Action1 resided QTest::mouseClick(win.windowHandle(), Qt::LeftButton, Qt::NoModifier, win.menuBar()->geometry().center()); QCoreApplication::sendPostedEvents(); // make sure all queued events also dispatched - QCOMPARE(spy.count(), 0); + QCOMPARE(spy.size(), 0); +} + +void tst_QMenuBar::pressDragRelease_data() +{ + QTest::addColumn<QPointingDevice *>("device"); + + QTest::newRow("mouse") << const_cast<QPointingDevice *>(QPointingDevice::primaryPointingDevice()); + QTest::newRow("touchscreen") << m_touchScreen.get(); +} + +void tst_QMenuBar::pressDragRelease() +{ + QFETCH(QPointingDevice *, device); + + QMainWindow w; + const TestMenu menu = initWindowWithComplexMenuBar(w); + const QMenu *firstMenu = menu.menus.first(); + QAction *hoveredAction = nullptr; + connect(firstMenu, &QMenu::hovered, firstMenu, [&hoveredAction](QAction *hov) { hoveredAction = hov; }); + w.show(); + QVERIFY(QTest::qWaitForWindowActive(&w)); + QWindow *win = w.windowHandle(); + const QPoint p1(50, w.menuBar()->geometry().height() / 2); + switch (device->type()) { + case QInputDevice::DeviceType::Mouse: + case QInputDevice::DeviceType::TouchPad: + QTest::mousePress(win, Qt::LeftButton, {}, p1); + break; + case QInputDevice::DeviceType::TouchScreen: + QTest::touchEvent(win, device).press(0, p1); + break; + default: + break; + } + + QTRY_VERIFY(firstMenu->isVisible()); + const QPoint firstMenuItemPos = firstMenu->geometry().center() - QPoint(0, 2); + const QPoint firstMenuItemPosInWin = w.mapFromGlobal(firstMenuItemPos); + switch (device->type()) { + case QInputDevice::DeviceType::Mouse: + case QInputDevice::DeviceType::TouchPad: + QTest::mouseMove(win, firstMenuItemPosInWin); + break; + case QInputDevice::DeviceType::TouchScreen: + QTest::touchEvent(win, device).move(0, firstMenuItemPosInWin); + break; + default: + break; + } + QVERIFY(hoveredAction); + QCOMPARE(hoveredAction, firstMenu->actionAt(firstMenu->mapFromGlobal(firstMenuItemPos))); + QSignalSpy triggeredSpy(hoveredAction, &QAction::triggered); + switch (device->type()) { + case QInputDevice::DeviceType::Mouse: + case QInputDevice::DeviceType::TouchPad: + QTest::mouseRelease(win, Qt::LeftButton, {}, firstMenuItemPosInWin); + break; + case QInputDevice::DeviceType::TouchScreen: + QTest::touchEvent(win, device).release(0, firstMenuItemPosInWin); + break; + default: + break; + } + QTRY_COMPARE(triggeredSpy.size(), 1); } // QTBUG-56526 @@ -1710,20 +1552,19 @@ void tst_QMenuBar::QTBUG_25669_menubarActionDoubleTriggered() QSignalSpy spy(win.menuBar(), &QMenuBar::triggered); win.show(); - QApplication::setActiveWindow(&win); QVERIFY(QTest::qWaitForWindowExposed(&win)); QPoint posAct1 = menuBarActionWindowPos(win.menuBar(), act1); QPoint posAct2 = menuBarActionWindowPos(win.menuBar(), act2); QTest::mouseClick(win.windowHandle(), Qt::LeftButton, Qt::NoModifier, posAct1); - QTRY_COMPARE(spy.count(), 1); + QTRY_COMPARE(spy.size(), 1); QTest::mouseClick(win.windowHandle(), Qt::LeftButton, Qt::NoModifier, posAct2); - QTRY_COMPARE(spy.count(), 2); + QTRY_COMPARE(spy.size(), 2); QTest::mouseClick(win.windowHandle(), Qt::LeftButton, Qt::NoModifier, posAct2); - QTRY_COMPARE(spy.count(), 3); + QTRY_COMPARE(spy.size(), 3); } void tst_QMenuBar::slotForTaskQTBUG53205() @@ -1747,7 +1588,6 @@ void tst_QMenuBar::taskQTBUG46812_doNotLeaveMenubarHighlighted() initWindowWithSimpleMenuBar(mainWindow); mainWindow.show(); - QApplication::setActiveWindow(&mainWindow); QVERIFY(QTest::qWaitForWindowActive(&mainWindow)); QVERIFY(!mainWindow.menuBar()->hasFocus()); @@ -1816,6 +1656,32 @@ void tst_QMenuBar::QTBUG_57404_existingMenuItemException() QTest::qWait(100); // No crash, all fine. Ideally, there should be only one warning. } + +void tst_QMenuBar::defaultEditMenuItems() +{ + class TestTranslator : public QTranslator + { + public: + QString translate(const char *context, const char *sourceText, + const char *disambiguation = nullptr, int n = -1) const override + { + if (QByteArrayView(context) == "QCocoaMenu" && QByteArrayView(sourceText) == "Edit") + return QString("Editieren"); + return QTranslator::translate(context, sourceText, disambiguation, n); + } + } testTranslator; + qApp->installTranslator(&testTranslator); + + QMainWindow mw; + mw.show(); + QVERIFY(QTest::qWaitForWindowActive(&mw)); + + mw.menuBar()->addMenu("Editieren")->addAction("Undo"); + + mw.hide(); + mw.show(); + // this should not crash with infinite recursion +} #endif // Q_OS_MACOS void tst_QMenuBar::taskQTBUG55966_subMenuRemoved() @@ -1833,7 +1699,6 @@ void tst_QMenuBar::taskQTBUG55966_subMenuRemoved() delete subMenu; window.show(); - QApplication::setActiveWindow(&window); QVERIFY(QTest::qWaitForWindowActive(&window)); QTest::qWait(500); } diff --git a/tests/auto/widgets/widgets/qmenubar/tst_qmenubar_mac.mm b/tests/auto/widgets/widgets/qmenubar/tst_qmenubar_mac.mm index 823ca7edfa..55e983a4d1 100644 --- a/tests/auto/widgets/widgets/qmenubar/tst_qmenubar_mac.mm +++ b/tests/auto/widgets/widgets/qmenubar/tst_qmenubar_mac.mm @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2017 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #import <Cocoa/Cocoa.h> |