aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMitch Curtis <mitch.curtis@qt.io>2022-07-29 14:26:50 +0800
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2022-08-25 05:44:33 +0000
commitcd556bfef0ecbdba3ac60fcab6393167686782ef (patch)
treecaef6217823e6b1c75f4c7b3b27665ebbd961dbc /tests
parent659938419669b831c156f33a6be0538d319d413e (diff)
Platform: fix MenuItem being triggered when disabled
Ensure that we remove shortcuts for a MenuItem when it's disabled, not just when a new shortcut is set. Fixes: QTBUG-89567 Change-Id: I9c4eeda1a68a23317fe5e7bf517046e4e403c46a Reviewed-by: Oliver Eftevaag <oliver.eftevaag@qt.io> (cherry picked from commit acf2ed0c5fb7594ab01ff48e3dc5c3c16e203755) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/quickcontrols2/platform/CMakeLists.txt1
-rw-r--r--tests/auto/quickcontrols2/platform/data/tst_menu.qml71
-rw-r--r--tests/auto/quickcontrols2/platform/tst_platform.cpp28
3 files changed, 99 insertions, 1 deletions
diff --git a/tests/auto/quickcontrols2/platform/CMakeLists.txt b/tests/auto/quickcontrols2/platform/CMakeLists.txt
index 6633de5c02..8e6df7d2b4 100644
--- a/tests/auto/quickcontrols2/platform/CMakeLists.txt
+++ b/tests/auto/quickcontrols2/platform/CMakeLists.txt
@@ -17,6 +17,7 @@ qt_internal_add_test(tst_platform
tst_platform.cpp
PUBLIC_LIBRARIES
Qt::Gui
+ Qt::Qml
TESTDATA ${test_data}
)
diff --git a/tests/auto/quickcontrols2/platform/data/tst_menu.qml b/tests/auto/quickcontrols2/platform/data/tst_menu.qml
index 00a75fe110..fb9949c8b7 100644
--- a/tests/auto/quickcontrols2/platform/data/tst_menu.qml
+++ b/tests/auto/quickcontrols2/platform/data/tst_menu.qml
@@ -4,6 +4,8 @@
import QtQuick
import QtTest
import Qt.labs.platform
+import QtQuick.Controls as Controls
+import org.qtproject.Test
TestCase {
id: testCase
@@ -28,6 +30,11 @@ TestCase {
signalName: "itemsChanged"
}
+ Component {
+ id: signalSpyComponent
+ SignalSpy {}
+ }
+
function init() {
verify(!itemsSpy.target)
compare(itemsSpy.count, 0)
@@ -214,4 +221,68 @@ TestCase {
compare(subMenu.title, "Title")
compare(subMenuItem.text, "Title")
}
+
+ Component {
+ id: disabledMenuItemAndActionComponent
+
+ Item {
+ property alias action: action
+ property alias menu: menu
+
+ Controls.Action {
+ id: action
+ shortcut: StandardKey.Copy
+ }
+
+ Menu {
+ id: menu
+
+ MenuItem {
+ enabled: !action.enabled
+ shortcut: StandardKey.Copy
+ text: "test"
+ }
+ }
+ }
+ }
+
+ function test_shortcuts() {
+ if (!TestHelper.shortcutsSupported)
+ skip("This test requires shortcut support")
+
+ let root = createTemporaryObject(disabledMenuItemAndActionComponent, testCase)
+ verify(root)
+ let menu = root.menu
+ let menuItem = menu.items[0]
+ verify(menuItem)
+ let action = root.action
+
+ let actionTriggeredSpy = signalSpyComponent.createObject(root,
+ { target: action, signalName: "triggered" })
+ verify(actionTriggeredSpy.valid)
+ let menuItemTriggeredSpy = signalSpyComponent.createObject(root,
+ { target: menuItem, signalName: "triggered" })
+ verify(menuItemTriggeredSpy.valid)
+
+ // Perform the shortcut; the Action should be triggered since the MenuItem is disabled.
+ keySequence(StandardKey.Copy)
+ compare(actionTriggeredSpy.count, 1)
+ compare(menuItemTriggeredSpy.count, 0)
+
+ // Disable the Action, enabling the MenuItem in the process.
+ action.enabled = false
+ verify(menuItem.enabled)
+ // Perform the shortcut; the MenuItem should be triggered since the Action is disabled.
+ keySequence(StandardKey.Copy)
+ compare(actionTriggeredSpy.count, 1)
+ compare(menuItemTriggeredSpy.count, 1)
+
+ // Re-enable the Action, disabling the MenuItem in the process.
+ action.enabled = true
+ verify(!menuItem.enabled)
+ // Perform the shortcut; the Action should be triggered since the MenuItem is disabled.
+ keySequence(StandardKey.Copy)
+ compare(actionTriggeredSpy.count, 2)
+ compare(menuItemTriggeredSpy.count, 1)
+ }
}
diff --git a/tests/auto/quickcontrols2/platform/tst_platform.cpp b/tests/auto/quickcontrols2/platform/tst_platform.cpp
index 335ad9b533..94bf1d6a59 100644
--- a/tests/auto/quickcontrols2/platform/tst_platform.cpp
+++ b/tests/auto/quickcontrols2/platform/tst_platform.cpp
@@ -1,5 +1,31 @@
// Copyright (C) 2017 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+#include <QtQml/qqmlengine.h>
#include <QtQuickTest/quicktest.h>
-QUICK_TEST_MAIN(tst_platform)
+
+class Setup : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(bool shortcutsSupported READ areShortcutsSupported CONSTANT FINAL)
+
+public:
+ bool areShortcutsSupported() const
+ {
+#if QT_CONFIG(shortcut)
+ return true;
+#else
+ return false;
+#endif
+ }
+
+public slots:
+ void qmlEngineAvailable(QQmlEngine *)
+ {
+ qmlRegisterSingletonInstance("org.qtproject.Test", 1, 0, "TestHelper", this);
+ }
+};
+
+QUICK_TEST_MAIN_WITH_SETUP(tst_platform, Setup)
+
+#include "tst_platform.moc"