aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qquickmenu
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@qt.io>2017-09-27 15:14:32 +0200
committerJ-P Nurmi <jpnurmi@qt.io>2017-09-27 13:42:30 +0000
commit576a97774e04858adee9f2080e485a715e985820 (patch)
tree32b2327d90713ed345d51fdd5bb51cbbe79615cc /tests/auto/qquickmenu
parent125c08cad177edf8baba9a6ca84425255db9c500 (diff)
Rename tst_menu to tst_QQuickMenu
Change-Id: I1c7e1a2b337e9d16bc6c9b098db08f29f1b9d1e6 Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'tests/auto/qquickmenu')
-rw-r--r--tests/auto/qquickmenu/data/addItem.qml71
-rw-r--r--tests/auto/qquickmenu/data/applicationwindow.qml91
-rw-r--r--tests/auto/qquickmenu/data/menuSeparator.qml83
-rw-r--r--tests/auto/qquickmenu/data/order.qml81
-rw-r--r--tests/auto/qquickmenu/data/pressAndHold.qml73
-rw-r--r--tests/auto/qquickmenu/data/repeater.qml69
-rw-r--r--tests/auto/qquickmenu/qquickmenu.pro15
-rw-r--r--tests/auto/qquickmenu/tst_qquickmenu.cpp482
8 files changed, 965 insertions, 0 deletions
diff --git a/tests/auto/qquickmenu/data/addItem.qml b/tests/auto/qquickmenu/data/addItem.qml
new file mode 100644
index 00000000..0668e439
--- /dev/null
+++ b/tests/auto/qquickmenu/data/addItem.qml
@@ -0,0 +1,71 @@
+/****************************************************************************
+**
+** 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:BSD$
+** 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.
+**
+** BSD License Usage
+** Alternatively, you may use this file under the terms of the BSD license
+** as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of The Qt Company Ltd nor the names of its
+** contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQuick 2.6
+import QtQuick.Controls 2.1
+
+ApplicationWindow {
+ width: 200
+ height: 200
+
+ property alias menu: menu
+
+ MenuItem {
+ id: newMenuItem
+ text: qsTr("New")
+ }
+
+ Menu {
+ id: menu
+ y: parent.height
+
+ Component.onCompleted: addItem(newMenuItem)
+ }
+}
diff --git a/tests/auto/qquickmenu/data/applicationwindow.qml b/tests/auto/qquickmenu/data/applicationwindow.qml
new file mode 100644
index 00000000..265a2f1a
--- /dev/null
+++ b/tests/auto/qquickmenu/data/applicationwindow.qml
@@ -0,0 +1,91 @@
+/****************************************************************************
+**
+** 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:BSD$
+** 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.
+**
+** BSD License Usage
+** Alternatively, you may use this file under the terms of the BSD license
+** as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of The Qt Company Ltd nor the names of its
+** contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQuick 2.6
+import QtQuick.Controls 2.1
+
+ApplicationWindow {
+ title: "Test Application Window"
+ width: 400
+ height: 400
+
+ property alias emptyMenu: emptyMenu
+ property alias menu: menu
+ property alias menuButton: menuButton
+
+ Menu {
+ id: emptyMenu
+ }
+
+ Menu {
+ id: menu
+
+ MenuItem {
+ objectName: "firstMenuItem"
+ text: "A"
+ }
+ MenuItem {
+ objectName: "secondMenuItem"
+ text: "B"
+ }
+ MenuItem {
+ objectName: "thirdMenuItem"
+ text: "C"
+ }
+ }
+
+ Button {
+ id: menuButton
+ x: 250
+ visible: false
+ text: "Open Menu"
+ onClicked: menu.open()
+ }
+}
diff --git a/tests/auto/qquickmenu/data/menuSeparator.qml b/tests/auto/qquickmenu/data/menuSeparator.qml
new file mode 100644
index 00000000..6cdf8b27
--- /dev/null
+++ b/tests/auto/qquickmenu/data/menuSeparator.qml
@@ -0,0 +1,83 @@
+/****************************************************************************
+**
+** 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:BSD$
+** 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.
+**
+** BSD License Usage
+** Alternatively, you may use this file under the terms of the BSD license
+** as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of The Qt Company Ltd nor the names of its
+** contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQuick 2.6
+import QtQuick.Controls 2.1
+
+ApplicationWindow {
+ width: 200
+ height: 200
+
+ property alias menu: menu
+
+ MenuItem {
+ id: newMenuItem
+ text: qsTr("New")
+ }
+
+ MenuSeparator {
+ id: menuSeparator
+ }
+
+ MenuItem {
+ id: saveMenuItem
+ text: qsTr("Save")
+ }
+
+ Menu {
+ id: menu
+
+ Component.onCompleted: {
+ addItem(newMenuItem)
+ addItem(menuSeparator)
+ addItem(saveMenuItem)
+ }
+ }
+}
diff --git a/tests/auto/qquickmenu/data/order.qml b/tests/auto/qquickmenu/data/order.qml
new file mode 100644
index 00000000..db5c3c1a
--- /dev/null
+++ b/tests/auto/qquickmenu/data/order.qml
@@ -0,0 +1,81 @@
+/****************************************************************************
+**
+** 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:BSD$
+** 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.
+**
+** BSD License Usage
+** Alternatively, you may use this file under the terms of the BSD license
+** as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of The Qt Company Ltd nor the names of its
+** contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQuick 2.6
+import QtQuick.Controls 2.1
+
+ApplicationWindow {
+ width: 200
+ height: 200
+
+ property alias menu: menu
+
+ Component {
+ id: menuItem
+ MenuItem { }
+ }
+
+ Menu {
+ id: menu
+ property alias repeater: repeater
+ MenuItem { text: "static_1" }
+ Repeater {
+ id: repeater
+ model: 2
+ MenuItem { text: "repeated_" + (index + 2) }
+ }
+ MenuItem { text: "static_4" }
+ Component.onCompleted: {
+ addItem(menuItem.createObject(menu.contentItem, {text: "dynamic_5"}))
+ addItem(menuItem.createObject(menu.contentItem, {text: "dynamic_6"}))
+ insertItem(0, menuItem.createObject(menu.contentItem, {text: "dynamic_0"}))
+ }
+ }
+}
diff --git a/tests/auto/qquickmenu/data/pressAndHold.qml b/tests/auto/qquickmenu/data/pressAndHold.qml
new file mode 100644
index 00000000..6f0acd3a
--- /dev/null
+++ b/tests/auto/qquickmenu/data/pressAndHold.qml
@@ -0,0 +1,73 @@
+/****************************************************************************
+**
+** 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:BSD$
+** 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.
+**
+** BSD License Usage
+** Alternatively, you may use this file under the terms of the BSD license
+** as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of The Qt Company Ltd nor the names of its
+** contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQuick 2.6
+import QtQuick.Controls 2.1
+
+ApplicationWindow {
+ width: 400
+ height: 400
+
+ property alias menu: menu
+
+ MouseArea {
+ anchors.fill: parent
+ onPressAndHold: menu.open()
+ }
+
+ Menu {
+ id: menu
+ x: (parent.width - width) / 2
+ y: (parent.height - height) / 2
+ MenuItem { text: "One" }
+ MenuItem { text: "Two" }
+ MenuItem { text: "Three" }
+ }
+}
diff --git a/tests/auto/qquickmenu/data/repeater.qml b/tests/auto/qquickmenu/data/repeater.qml
new file mode 100644
index 00000000..2172f86a
--- /dev/null
+++ b/tests/auto/qquickmenu/data/repeater.qml
@@ -0,0 +1,69 @@
+/****************************************************************************
+**
+** 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:BSD$
+** 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.
+**
+** BSD License Usage
+** Alternatively, you may use this file under the terms of the BSD license
+** as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of The Qt Company Ltd nor the names of its
+** contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQuick 2.6
+import QtQuick.Controls 2.1
+
+ApplicationWindow {
+ width: 200
+ height: 200
+
+ property alias menu: menu
+ property alias repeater: repeater
+
+ Menu {
+ id: menu
+ Repeater {
+ id: repeater
+ model: 5
+ MenuItem { property int idx: index }
+ }
+ }
+}
diff --git a/tests/auto/qquickmenu/qquickmenu.pro b/tests/auto/qquickmenu/qquickmenu.pro
new file mode 100644
index 00000000..ee539842
--- /dev/null
+++ b/tests/auto/qquickmenu/qquickmenu.pro
@@ -0,0 +1,15 @@
+CONFIG += testcase
+TARGET = tst_qquickmenu
+SOURCES += tst_qquickmenu.cpp
+
+macos:CONFIG -= app_bundle
+
+QT += core-private gui-private qml-private quick-private testlib quicktemplates2-private
+
+include (../shared/util.pri)
+
+TESTDATA = data/*
+
+OTHER_FILES += \
+ data/*.qml
+
diff --git a/tests/auto/qquickmenu/tst_qquickmenu.cpp b/tests/auto/qquickmenu/tst_qquickmenu.cpp
new file mode 100644
index 00000000..717e892b
--- /dev/null
+++ b/tests/auto/qquickmenu/tst_qquickmenu.cpp
@@ -0,0 +1,482 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL3$
+** 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 http://www.qt.io/terms-conditions. For further
+** information use the contact form at http://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPLv3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or later as published by the Free
+** Software Foundation and appearing in the file LICENSE.GPL included in
+** the packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 2.0 requirements will be
+** met: http://www.gnu.org/licenses/gpl-2.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <qtest.h>
+#include <QtTest/QSignalSpy>
+#include <QtGui/qstylehints.h>
+#include <QtQml/qqmlengine.h>
+#include <QtQml/qqmlcomponent.h>
+#include <QtQml/qqmlcontext.h>
+#include <QtQuick/qquickview.h>
+#include <QtQuick/private/qquickitem_p.h>
+#include "../shared/util.h"
+#include "../shared/visualtestutil.h"
+
+#include <QtQuickTemplates2/private/qquickapplicationwindow_p.h>
+#include <QtQuickTemplates2/private/qquickoverlay_p.h>
+#include <QtQuickTemplates2/private/qquickbutton_p.h>
+#include <QtQuickTemplates2/private/qquickmenu_p.h>
+#include <QtQuickTemplates2/private/qquickmenuitem_p.h>
+#include <QtQuickTemplates2/private/qquickmenuseparator_p.h>
+
+using namespace QQuickVisualTestUtil;
+
+class tst_QQuickMenu : public QQmlDataTest
+{
+ Q_OBJECT
+
+public:
+
+private slots:
+ void defaults();
+ void mouse();
+ void pressAndHold();
+ void contextMenuKeyboard();
+ void menuButton();
+ void addItem();
+ void menuSeparator();
+ void repeater();
+ void order();
+};
+
+void tst_QQuickMenu::defaults()
+{
+ QQuickApplicationHelper helper(this, QLatin1String("applicationwindow.qml"));
+
+ QQuickMenu *emptyMenu = helper.appWindow->property("emptyMenu").value<QQuickMenu*>();
+ QCOMPARE(emptyMenu->isVisible(), false);
+ QCOMPARE(emptyMenu->contentItem()->property("currentIndex"), QVariant(-1));
+}
+
+void tst_QQuickMenu::mouse()
+{
+ QQuickApplicationHelper helper(this, QLatin1String("applicationwindow.qml"));
+
+ QQuickApplicationWindow *window = helper.appWindow;
+ window->show();
+ QVERIFY(QTest::qWaitForWindowActive(window));
+
+ QQuickMenu *menu = window->property("menu").value<QQuickMenu*>();
+ menu->open();
+ QVERIFY(menu->isVisible());
+ QVERIFY(window->overlay()->childItems().contains(menu->contentItem()->parentItem()));
+
+ QQuickItem *firstItem = menu->itemAt(0);
+ QSignalSpy clickedSpy(firstItem, SIGNAL(clicked()));
+ QSignalSpy triggeredSpy(firstItem, SIGNAL(triggered()));
+ QSignalSpy visibleSpy(menu, SIGNAL(visibleChanged()));
+
+ // Ensure that presses cause the current index to change,
+ // so that the highlight acts as a way of illustrating press state.
+ QTest::mousePress(window, Qt::LeftButton, Qt::NoModifier, QPoint(firstItem->width() / 2, firstItem->height() / 2));
+ QVERIFY(firstItem->hasActiveFocus());
+ QCOMPARE(menu->contentItem()->property("currentIndex"), QVariant(0));
+ QVERIFY(menu->isVisible());
+
+ QTest::mouseRelease(window, Qt::LeftButton, Qt::NoModifier, QPoint(firstItem->width() / 2, firstItem->height() / 2));
+ QCOMPARE(clickedSpy.count(), 1);
+ QCOMPARE(triggeredSpy.count(), 1);
+ QCOMPARE(visibleSpy.count(), 1);
+ QVERIFY(!menu->isVisible());
+ QVERIFY(!window->overlay()->childItems().contains(menu->contentItem()));
+ QCOMPARE(menu->contentItem()->property("currentIndex"), QVariant(-1));
+
+ menu->open();
+ QCOMPARE(visibleSpy.count(), 2);
+ QVERIFY(menu->isVisible());
+ QVERIFY(window->overlay()->childItems().contains(menu->contentItem()->parentItem()));
+
+ // Ensure that we have enough space to click outside of the menu.
+ QVERIFY(window->width() > menu->contentItem()->width());
+ QVERIFY(window->height() > menu->contentItem()->height());
+ QTest::mouseClick(window, Qt::LeftButton, Qt::NoModifier,
+ QPoint(menu->contentItem()->width() + 1, menu->contentItem()->height() + 1));
+ QCOMPARE(visibleSpy.count(), 3);
+ QVERIFY(!menu->isVisible());
+ QVERIFY(!window->overlay()->childItems().contains(menu->contentItem()->parentItem()));
+
+ menu->open();
+ QCOMPARE(visibleSpy.count(), 4);
+ QVERIFY(menu->isVisible());
+ QVERIFY(window->overlay()->childItems().contains(menu->contentItem()->parentItem()));
+
+ // Try pressing within the menu and releasing outside of it; it should close.
+ // TODO: won't work until QQuickPopup::releasedOutside() actually gets emitted
+// QTest::mousePress(window, Qt::LeftButton, Qt::NoModifier, QPoint(firstItem->width() / 2, firstItem->height() / 2));
+// QVERIFY(firstItem->hasActiveFocus());
+// QCOMPARE(menu->contentItem()->property("currentIndex"), QVariant(0));
+// QVERIFY(menu->isVisible());
+// QCOMPARE(triggeredSpy.count(), 1);
+
+// QTest::mouseRelease(window, Qt::LeftButton, Qt::NoModifier, QPoint(menu->contentItem()->width() + 1, firstItem->height() / 2));
+// QCOMPARE(clickedSpy.count(), 1);
+// QCOMPARE(triggeredSpy.count(), 1);
+// QCOMPARE(visibleSpy.count(), 5);
+// QVERIFY(!menu->isVisible());
+// QVERIFY(!window->overlay()->childItems().contains(menu->contentItem()));
+// QCOMPARE(menu->contentItem()->property("currentIndex"), QVariant(-1));
+}
+
+void tst_QQuickMenu::pressAndHold()
+{
+ QQuickApplicationHelper helper(this, QLatin1String("pressAndHold.qml"));
+
+ QQuickWindow *window = helper.window;
+ window->show();
+ QVERIFY(QTest::qWaitForWindowActive(window));
+
+ QQuickMenu *menu = window->property("menu").value<QQuickMenu *>();
+ QVERIFY(menu);
+
+ QTest::mousePress(window, Qt::LeftButton, Qt::NoModifier, QPoint(1, 1));
+ QTRY_VERIFY(menu->isVisible());
+
+ QTest::mouseRelease(window, Qt::LeftButton, Qt::NoModifier, QPoint(1, 1));
+ QVERIFY(menu->isVisible());
+
+ QTest::mouseClick(window, Qt::LeftButton, Qt::NoModifier, QPoint(1, 1));
+ QTRY_VERIFY(!menu->isVisible());
+}
+
+void tst_QQuickMenu::contextMenuKeyboard()
+{
+ if (QGuiApplication::styleHints()->tabFocusBehavior() != Qt::TabFocusAllControls)
+ QSKIP("This platform only allows tab focus for text controls");
+
+ QQuickApplicationHelper helper(this, QLatin1String("applicationwindow.qml"));
+
+ QQuickApplicationWindow *window = helper.appWindow;
+ window->show();
+ window->requestActivate();
+ QVERIFY(QTest::qWaitForWindowActive(window));
+ QVERIFY(QGuiApplication::focusWindow() == window);
+
+ QQuickMenu *menu = window->property("menu").value<QQuickMenu*>();
+ QCOMPARE(menu->contentItem()->property("currentIndex"), QVariant(-1));
+
+ QQuickMenuItem *firstItem = qobject_cast<QQuickMenuItem *>(menu->itemAt(0));
+ QVERIFY(firstItem);
+ QSignalSpy visibleSpy(menu, SIGNAL(visibleChanged()));
+
+ menu->setFocus(true);
+ menu->open();
+ QCOMPARE(visibleSpy.count(), 1);
+ QVERIFY(menu->isVisible());
+ QVERIFY(window->overlay()->childItems().contains(menu->contentItem()->parentItem()));
+ QVERIFY(!firstItem->hasActiveFocus());
+ QCOMPARE(menu->contentItem()->property("currentIndex"), QVariant(-1));
+
+ QTest::keyClick(window, Qt::Key_Tab);
+ QVERIFY(firstItem->hasActiveFocus());
+ QVERIFY(firstItem->hasVisualFocus());
+ QCOMPARE(firstItem->focusReason(), Qt::TabFocusReason);
+ QCOMPARE(menu->contentItem()->property("currentIndex"), QVariant(0));
+
+ QQuickMenuItem *secondItem = qobject_cast<QQuickMenuItem *>(menu->itemAt(1));
+ QVERIFY(secondItem);
+ QTest::keyClick(window, Qt::Key_Tab);
+ QVERIFY(!firstItem->hasActiveFocus());
+ QVERIFY(!firstItem->hasVisualFocus());
+ QVERIFY(secondItem->hasActiveFocus());
+ QVERIFY(secondItem->hasVisualFocus());
+ QCOMPARE(secondItem->focusReason(), Qt::TabFocusReason);
+ QCOMPARE(menu->contentItem()->property("currentIndex"), QVariant(1));
+
+ QSignalSpy secondTriggeredSpy(secondItem, SIGNAL(triggered()));
+ QTest::keyClick(window, Qt::Key_Space);
+ QCOMPARE(secondTriggeredSpy.count(), 1);
+ QCOMPARE(visibleSpy.count(), 2);
+ QVERIFY(!menu->isVisible());
+ QVERIFY(!window->overlay()->childItems().contains(menu->contentItem()));
+ QVERIFY(!firstItem->hasActiveFocus());
+ QVERIFY(!firstItem->hasVisualFocus());
+ QVERIFY(!secondItem->hasActiveFocus());
+ QVERIFY(!secondItem->hasVisualFocus());
+ QCOMPARE(menu->contentItem()->property("currentIndex"), QVariant(-1));
+
+ menu->open();
+ QCOMPARE(visibleSpy.count(), 3);
+ QVERIFY(menu->isVisible());
+ QVERIFY(window->overlay()->childItems().contains(menu->contentItem()->parentItem()));
+ QVERIFY(!firstItem->hasActiveFocus());
+ QVERIFY(!firstItem->hasVisualFocus());
+ QVERIFY(!secondItem->hasActiveFocus());
+ QVERIFY(!secondItem->hasVisualFocus());
+ QCOMPARE(menu->contentItem()->property("currentIndex"), QVariant(-1));
+
+ QTest::keyClick(window, Qt::Key_Down);
+ QVERIFY(firstItem->hasActiveFocus());
+ QVERIFY(firstItem->hasVisualFocus());
+ QCOMPARE(firstItem->focusReason(), Qt::TabFocusReason);
+
+ QTest::keyClick(window, Qt::Key_Down);
+ QVERIFY(secondItem->hasActiveFocus());
+ QVERIFY(secondItem->hasVisualFocus());
+ QCOMPARE(secondItem->focusReason(), Qt::TabFocusReason);
+
+ QTest::keyClick(window, Qt::Key_Down);
+ QQuickMenuItem *thirdItem = qobject_cast<QQuickMenuItem *>(menu->itemAt(2));
+ QVERIFY(thirdItem);
+ QVERIFY(!firstItem->hasActiveFocus());
+ QVERIFY(!firstItem->hasVisualFocus());
+ QVERIFY(!secondItem->hasActiveFocus());
+ QVERIFY(!secondItem->hasVisualFocus());
+ QVERIFY(thirdItem->hasActiveFocus());
+ QVERIFY(thirdItem->hasVisualFocus());
+ QCOMPARE(thirdItem->focusReason(), Qt::TabFocusReason);
+
+ // Key navigation shouldn't wrap by default.
+ QTest::keyClick(window, Qt::Key_Down);
+ QVERIFY(!firstItem->hasActiveFocus());
+ QVERIFY(!firstItem->hasVisualFocus());
+ QVERIFY(!secondItem->hasActiveFocus());
+ QVERIFY(!secondItem->hasVisualFocus());
+ QVERIFY(thirdItem->hasActiveFocus());
+ QVERIFY(thirdItem->hasVisualFocus());
+ QCOMPARE(thirdItem->focusReason(), Qt::TabFocusReason);
+
+ QTest::keyClick(window, Qt::Key_Up);
+ QVERIFY(!firstItem->hasActiveFocus());
+ QVERIFY(!firstItem->hasVisualFocus());
+ QVERIFY(secondItem->hasActiveFocus());
+ QVERIFY(secondItem->hasVisualFocus());
+ QCOMPARE(secondItem->focusReason(), Qt::BacktabFocusReason);
+ QVERIFY(!thirdItem->hasActiveFocus());
+ QVERIFY(!thirdItem->hasVisualFocus());
+
+ QTest::keyClick(window, Qt::Key_Backtab);
+ QVERIFY(firstItem->hasActiveFocus());
+ QVERIFY(firstItem->hasVisualFocus());
+ QCOMPARE(firstItem->focusReason(), Qt::BacktabFocusReason);
+ QVERIFY(!secondItem->hasActiveFocus());
+ QVERIFY(!secondItem->hasVisualFocus());
+ QVERIFY(!thirdItem->hasActiveFocus());
+ QVERIFY(!thirdItem->hasVisualFocus());
+
+ QTest::keyClick(window, Qt::Key_Escape);
+ QCOMPARE(visibleSpy.count(), 4);
+ QVERIFY(!menu->isVisible());
+}
+
+void tst_QQuickMenu::menuButton()
+{
+ if (QGuiApplication::styleHints()->tabFocusBehavior() != Qt::TabFocusAllControls)
+ QSKIP("This platform only allows tab focus for text controls");
+
+ QQuickApplicationHelper helper(this, QLatin1String("applicationwindow.qml"));
+
+ QQuickApplicationWindow *window = helper.appWindow;
+ window->show();
+ window->requestActivate();
+ QVERIFY(QTest::qWaitForWindowActive(window));
+ QVERIFY(QGuiApplication::focusWindow() == window);
+
+ QQuickMenu *menu = window->property("menu").value<QQuickMenu*>();
+ QQuickButton *menuButton = window->property("menuButton").value<QQuickButton*>();
+ QSignalSpy visibleSpy(menu, SIGNAL(visibleChanged()));
+
+ menuButton->setVisible(true);
+ QTest::mouseClick(window, Qt::LeftButton, Qt::NoModifier,
+ menuButton->mapToScene(QPointF(menuButton->width() / 2, menuButton->height() / 2)).toPoint());
+ QCOMPARE(visibleSpy.count(), 1);
+ QVERIFY(menu->isVisible());
+
+ QTest::keyClick(window, Qt::Key_Tab);
+ QQuickItem *firstItem = menu->itemAt(0);
+ QVERIFY(firstItem->hasActiveFocus());
+}
+
+void tst_QQuickMenu::addItem()
+{
+ QQuickApplicationHelper helper(this, QLatin1String("addItem.qml"));
+ QQuickApplicationWindow *window = helper.appWindow;
+ window->show();
+ QVERIFY(QTest::qWaitForWindowActive(window));
+
+ QQuickMenu *menu = window->property("menu").value<QQuickMenu*>();
+ QVERIFY(menu);
+ menu->open();
+ QVERIFY(menu->isVisible());
+
+ QQuickItem *menuItem = menu->itemAt(0);
+ QVERIFY(menuItem);
+ QTRY_VERIFY(!QQuickItemPrivate::get(menuItem)->culled); // QTBUG-53262
+
+ QTest::mouseClick(window, Qt::LeftButton, Qt::NoModifier,
+ menuItem->mapToScene(QPointF(menuItem->width() / 2, menuItem->height() / 2)).toPoint());
+ QTRY_VERIFY(!menu->isVisible());
+}
+
+void tst_QQuickMenu::menuSeparator()
+{
+ QQuickApplicationHelper helper(this, QLatin1String("menuSeparator.qml"));
+ QQuickWindow *window = helper.window;
+ window->show();
+ QVERIFY(QTest::qWaitForWindowActive(window));
+
+ QQuickMenu *menu = window->property("menu").value<QQuickMenu*>();
+ QVERIFY(menu);
+ menu->open();
+ QVERIFY(menu->isVisible());
+
+ QQuickMenuItem *newMenuItem = qobject_cast<QQuickMenuItem*>(menu->itemAt(0));
+ QVERIFY(newMenuItem);
+ QCOMPARE(newMenuItem->text(), QStringLiteral("New"));
+
+ QQuickMenuSeparator *menuSeparator = qobject_cast<QQuickMenuSeparator*>(menu->itemAt(1));
+ QVERIFY(menuSeparator);
+
+ QQuickMenuItem *saveMenuItem = qobject_cast<QQuickMenuItem*>(menu->itemAt(2));
+ QVERIFY(saveMenuItem);
+ QCOMPARE(saveMenuItem->text(), QStringLiteral("Save"));
+ QTRY_VERIFY(!QQuickItemPrivate::get(saveMenuItem)->culled); // QTBUG-53262
+
+ // Clicking on items should still close the menu.
+ QTest::mouseClick(window, Qt::LeftButton, Qt::NoModifier,
+ newMenuItem->mapToScene(QPointF(newMenuItem->width() / 2, newMenuItem->height() / 2)).toPoint());
+ QTRY_VERIFY(!menu->isVisible());
+
+ menu->open();
+ QVERIFY(menu->isVisible());
+
+ // Clicking on a separator shouldn't close the menu.
+ QTest::mouseClick(window, Qt::LeftButton, Qt::NoModifier,
+ menuSeparator->mapToScene(QPointF(menuSeparator->width() / 2, menuSeparator->height() / 2)).toPoint());
+ QVERIFY(menu->isVisible());
+
+ // Clicking on items should still close the menu.
+ QTest::mouseClick(window, Qt::LeftButton, Qt::NoModifier,
+ saveMenuItem->mapToScene(QPointF(saveMenuItem->width() / 2, saveMenuItem->height() / 2)).toPoint());
+ QTRY_VERIFY(!menu->isVisible());
+
+ menu->open();
+ QVERIFY(menu->isVisible());
+
+ // Key navigation skips separators
+ QTest::keyClick(window, Qt::Key_Down);
+ QVERIFY(newMenuItem->hasActiveFocus());
+ QVERIFY(newMenuItem->hasVisualFocus());
+ QCOMPARE(newMenuItem->focusReason(), Qt::TabFocusReason);
+
+ QTest::keyClick(window, Qt::Key_Down);
+ QVERIFY(saveMenuItem->hasActiveFocus());
+ QVERIFY(saveMenuItem->hasVisualFocus());
+ QCOMPARE(saveMenuItem->focusReason(), Qt::TabFocusReason);
+
+ QTest::keyClick(window, Qt::Key_Down);
+ QVERIFY(saveMenuItem->hasActiveFocus());
+ QVERIFY(saveMenuItem->hasVisualFocus());
+ QCOMPARE(saveMenuItem->focusReason(), Qt::TabFocusReason);
+
+ QTest::keyClick(window, Qt::Key_Up);
+ QVERIFY(newMenuItem->hasActiveFocus());
+ QVERIFY(newMenuItem->hasVisualFocus());
+ QCOMPARE(newMenuItem->focusReason(), Qt::BacktabFocusReason);
+
+ QTest::keyClick(window, Qt::Key_Up);
+ QVERIFY(newMenuItem->hasActiveFocus());
+ QVERIFY(newMenuItem->hasVisualFocus());
+ QCOMPARE(newMenuItem->focusReason(), Qt::BacktabFocusReason);
+}
+
+void tst_QQuickMenu::repeater()
+{
+ QQuickApplicationHelper helper(this, QLatin1String("repeater.qml"));
+ QQuickWindow *window = helper.window;
+ window->show();
+ QVERIFY(QTest::qWaitForWindowActive(window));
+
+ QQuickMenu *menu = window->property("menu").value<QQuickMenu*>();
+ QVERIFY(menu);
+ menu->open();
+ QVERIFY(menu->isVisible());
+
+ QObject *repeater = window->property("repeater").value<QObject*>();
+ QVERIFY(repeater);
+
+ int count = repeater->property("count").toInt();
+ QCOMPARE(count, 5);
+
+ for (int i = 0; i < count; ++i) {
+ QQuickItem *item = menu->itemAt(i);
+ QVERIFY(item);
+ QCOMPARE(item->property("idx").toInt(), i);
+
+ QQuickItem *repeaterItem = nullptr;
+ QVERIFY(QMetaObject::invokeMethod(repeater, "itemAt", Q_RETURN_ARG(QQuickItem*, repeaterItem), Q_ARG(int, i)));
+ QCOMPARE(item, repeaterItem);
+ }
+
+ repeater->setProperty("model", 3);
+
+ count = repeater->property("count").toInt();
+ QCOMPARE(count, 3);
+
+ for (int i = 0; i < count; ++i) {
+ QQuickItem *item = menu->itemAt(i);
+ QVERIFY(item);
+ QCOMPARE(item->property("idx").toInt(), i);
+
+ QQuickItem *repeaterItem = nullptr;
+ QVERIFY(QMetaObject::invokeMethod(repeater, "itemAt", Q_RETURN_ARG(QQuickItem*, repeaterItem), Q_ARG(int, i)));
+ QCOMPARE(item, repeaterItem);
+ }
+}
+
+void tst_QQuickMenu::order()
+{
+ QQuickApplicationHelper helper(this, QLatin1String("order.qml"));
+ QQuickWindow *window = helper.window;
+ window->show();
+ QVERIFY(QTest::qWaitForWindowActive(window));
+
+ QQuickMenu *menu = window->property("menu").value<QQuickMenu*>();
+ QVERIFY(menu);
+ menu->open();
+ QVERIFY(menu->isVisible());
+
+ const QStringList texts = {"dynamic_0", "static_1", "repeated_2", "repeated_3", "static_4", "dynamic_5", "dynamic_6"};
+
+ for (int i = 0; i < texts.count(); ++i) {
+ QQuickItem *item = menu->itemAt(i);
+ QVERIFY(item);
+ QCOMPARE(item->property("text").toString(), texts.at(i));
+ }
+}
+
+QTEST_MAIN(tst_QQuickMenu)
+
+#include "tst_qquickmenu.moc"