diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/activeFocusOnTab/activeFocusOnTab.pro | 1 | ||||
-rw-r--r-- | tests/auto/auto.pro | 1 | ||||
-rw-r--r-- | tests/auto/controls/data/tst_menubar.qml | 43 | ||||
-rw-r--r-- | tests/auto/customcontrolsstyle/customcontrolsstyle.pro | 1 | ||||
-rw-r--r-- | tests/auto/dialogs/dialogs.pro | 6 | ||||
-rw-r--r-- | tests/auto/menubar/data/WindowWithMenuBar.qml | 122 | ||||
-rw-r--r-- | tests/auto/menubar/menubar.pro | 37 | ||||
-rw-r--r-- | tests/auto/menubar/tst_menubar.cpp | 252 |
8 files changed, 43 insertions, 420 deletions
diff --git a/tests/auto/activeFocusOnTab/activeFocusOnTab.pro b/tests/auto/activeFocusOnTab/activeFocusOnTab.pro index 47b14865..2a740a44 100644 --- a/tests/auto/activeFocusOnTab/activeFocusOnTab.pro +++ b/tests/auto/activeFocusOnTab/activeFocusOnTab.pro @@ -10,4 +10,3 @@ TESTDATA = data/* QT += core-private gui-private qml-private quick-private testlib !no_desktop: QT += widgets -DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0 diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro index 6b55a179..14860dc0 100644 --- a/tests/auto/auto.pro +++ b/tests/auto/auto.pro @@ -1,5 +1,4 @@ TEMPLATE = subdirs SUBDIRS += testplugin controls activeFocusOnTab applicationwindow dialogs \ extras qquicktreemodeladaptor customcontrolsstyle -!osx: SUBDIRS += menubar controls.depends = testplugin diff --git a/tests/auto/controls/data/tst_menubar.qml b/tests/auto/controls/data/tst_menubar.qml index 44238e21..329b43e7 100644 --- a/tests/auto/controls/data/tst_menubar.qml +++ b/tests/auto/controls/data/tst_menubar.qml @@ -83,6 +83,49 @@ TestCase { menuBar.destroy() } + function test_clickMenuBar() { + if (Qt.platform.os === "osx") + skip("MenuBar cannot be reliably tested on OS X") + + var window = windowComponent.createObject() + waitForRendering(window.contentItem) + var fileMenu = findChild(window, "fileMenu") + compare(fileMenu !== null, true) + // Click menu should open + compare(fileMenu.__popupVisible, false) + mouseClick(fileMenu.__visualItem) + tryCompare(fileMenu, "__popupVisible", true) + // wait until popup is visible + tryCompare(fileMenu.__contentItem, "status", Loader.Ready) + waitForRendering(fileMenu.__contentItem.item) + // Clicking on menu should close, we workaround the current + // implementation event routing of the TestCase suite. + // We send the event to an item that is child of the menupopupwindow + // to a a negative coordinate + mouseClick(fileMenu.__contentItem, 20, -13) + tryCompare(fileMenu, "__popupVisible", false) + window.destroy() + } + + function test_closeOnEscapePressed() { + if (Qt.platform.os === "osx") + skip("MenuBar cannot be reliably tested on OS X") + + var window = windowComponent.createObject() + waitForRendering(window.contentItem) + var fileMenu = findChild(window, "fileMenu") + verify(fileMenu) + // Click menu should open + compare(fileMenu.__popupVisible, false) + mouseClick(fileMenu.__visualItem) + tryCompare(fileMenu, "__popupVisible", true) + // wait until popup is visible + tryCompare(fileMenu.__contentItem, "status", Loader.Ready) + waitForRendering(fileMenu.__contentItem.item) + // Pressing escape should close the popup + keyPress(Qt.Key_Escape) + compare(fileMenu.__popupVisible, false) + } function test_qtBug47295() { diff --git a/tests/auto/customcontrolsstyle/customcontrolsstyle.pro b/tests/auto/customcontrolsstyle/customcontrolsstyle.pro index d3bcae47..ab50791e 100644 --- a/tests/auto/customcontrolsstyle/customcontrolsstyle.pro +++ b/tests/auto/customcontrolsstyle/customcontrolsstyle.pro @@ -6,7 +6,6 @@ include (../shared/util.pri) osx:CONFIG -= app_bundle -CONFIG += parallel_test QT += core-private qml-private quick-private testlib TESTDATA = data/* diff --git a/tests/auto/dialogs/dialogs.pro b/tests/auto/dialogs/dialogs.pro index cf46bed1..d8e15dea 100644 --- a/tests/auto/dialogs/dialogs.pro +++ b/tests/auto/dialogs/dialogs.pro @@ -5,16 +5,10 @@ SOURCES += tst_dialogs.cpp include (../shared/util.pri) osx:CONFIG -= app_bundle -osx:CONFIG+=insignificant_test # QTBUG-30513 - test is unstable -linux-*:CONFIG+=insignificant_test # QTBUG-30513 - test is unstable -win32:CONFIG+=insignificant_test # QTBUG-30513 - test is unstable -CONFIG += parallel_test QT += core-private gui-private qml-private quick-private testlib TESTDATA = data/* OTHER_FILES += \ data/RectWithFileDialog.qml - -DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0 diff --git a/tests/auto/menubar/data/WindowWithMenuBar.qml b/tests/auto/menubar/data/WindowWithMenuBar.qml deleted file mode 100644 index f4caf3f3..00000000 --- a/tests/auto/menubar/data/WindowWithMenuBar.qml +++ /dev/null @@ -1,122 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Copyright (C) 2015 Cucchetto Filippo <filippocucchetto@gmail.com> -** 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$ -** -****************************************************************************/ - -import QtQuick 2.2 -import QtQuick.Controls 1.2 - -ApplicationWindow { - id: root - objectName: "root" - visible: true - width: 400 - height: 400 - - menuBar: MenuBar { - id: menubar - objectName: "menuBar" - - Menu { - id: fileMenu - objectName: "fileMenu" - title: "&File" - - Menu { - id: actionsSubMenu - objectName: "actionsSubMenu" - title: "&Action" - - MenuItem { - id: loadMenuItem - objectName: "loadMenuItem" - text: "&Load" - } - - MenuItem { - id: saveMenuItem - objectName: "saveMenuItem" - text: "&Save" - } - } - - MenuItem { - id: exitMenuItem - objectName: "exitMenuItem" - text: "&Exit" - } - } - - Menu { - id: modifyMenu - objectName: "modifyMenu" - title: "&Modify" - - MenuItem { - id: preferencesMenuItem - objectName: "preferencesMenuItem" - text: "&Preferences" - } - } - } - - TextEdit { - id: centralTextEdit - objectName: "centralTextEdit" - anchors.centerIn: parent - width: 100 - height: 20 - } - - Menu { - id: contextMenu - objectName: "contextMenu" - MenuItem { - id: contextMenuItem1 - objectName: "contextMenuItem1" - text: "contextMenuItem1" - } - MenuItem { - id: contextMenuItem2 - objectName: "contextMenuItem2" - text: "contextMenuItem2" - } - } - - MouseArea { - anchors.fill: parent - onClicked: contextMenu.popup() - } -} diff --git a/tests/auto/menubar/menubar.pro b/tests/auto/menubar/menubar.pro deleted file mode 100644 index 663100da..00000000 --- a/tests/auto/menubar/menubar.pro +++ /dev/null @@ -1,37 +0,0 @@ -CONFIG += testcase console -TARGET = tst_menubar - -HEADERS += \ - $$PWD/../../../src/controls/qquickpopupwindow_p.h \ - $$PWD/../../../src/controls/qquickmenupopupwindow_p.h \ - $$PWD/../../../src/controls/qquickmenubar_p.h \ - $$PWD/../../../src/controls/qquickmenu_p.h \ - $$PWD/../../../src/controls/qquickmenuitem_p.h \ - $$PWD/../../../src/controls/qquickaction_p.h \ - $$PWD/../../../src/controls/qquickexclusivegroup_p.h \ - $$PWD/../../../src/controls/qquickmenuitemcontainer_p.h - -SOURCES += \ - tst_menubar.cpp \ - $$PWD/../../../src/controls/qquickpopupwindow.cpp \ - $$PWD/../../../src/controls/qquickmenupopupwindow.cpp \ - $$PWD/../../../src/controls/qquickmenubar.cpp \ - $$PWD/../../../src/controls/qquickmenu.cpp \ - $$PWD/../../../src/controls/qquickmenuitem.cpp \ - $$PWD/../../../src/controls/qquickaction.cpp \ - $$PWD/../../../src/controls/qquickexclusivegroup.cpp - -include (../shared/util.pri) - -linux-*:CONFIG+=insignificant_test # QTBUG-30513 - test is unstable -win32:CONFIG+=insignificant_test # QTBUG-30513 - test is unstable - -CONFIG += parallel_test -QT += core-private gui-private qml-private quick-private testlib - -INCLUDEPATH += $$PWD/../../../src/controls - -DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0 - -OTHER_FILES += \ - data/WindowWithMenuBar.qml diff --git a/tests/auto/menubar/tst_menubar.cpp b/tests/auto/menubar/tst_menubar.cpp deleted file mode 100644 index 29ef295f..00000000 --- a/tests/auto/menubar/tst_menubar.cpp +++ /dev/null @@ -1,252 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 The Qt Company Ltd. -** Copyright (C) 2015 Cucchetto Filippo <filippocucchetto@gmail.com> -** 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 "../shared/util.h" -#include <QtQuick/QQuickItem> -#include <QtQuick/QQuickWindow> -#include <QtQml/QQmlApplicationEngine> -#include <QSignalSpy> -#include <QTest> -#include "qquickmenupopupwindow_p.h" -#include "qquickpopupwindow_p.h" -#include "qquickmenu_p.h" - -#define WAIT_TIME 500 - - -class tst_menubar : public QQmlDataTest -{ - Q_OBJECT - -private slots: - void initTestCase() - { - QQmlDataTest::initTestCase(); - } - - void init(); - void cleanup(); - - void testParentMenuForPopupsOutsideMenuBar(); - void testParentMenuForPopupsInsideMenuBar(); - void testClickMenuBarSubMenu(); - void testClickMenuBarRootMenu(); - -private: - void moveOnPos(QObject *window, const QPoint &point); - void moveOnPos(const QPoint &point); - void clickOnPos(QObject *window, const QPoint &point); - void clickOnPos(const QPoint &point); - - QQmlApplicationEngine *m_engine; - QQuickWindow *m_window; - QObject *m_menuBar; -}; - -bool waitForRendering(QQuickWindow* window, int timeout = WAIT_TIME) -{ - QSignalSpy signalSpy(window, SIGNAL(frameSwapped())); - return signalSpy.wait(timeout); -} - -void tst_menubar::moveOnPos(QObject *window, const QPoint &point) -{ - qApp->sendEvent(window, new QMouseEvent(QEvent::MouseMove, - point, - Qt::NoButton, - Qt::NoButton, - 0)); -} - -void tst_menubar::moveOnPos(const QPoint &point) -{ - QPoint global = m_window->mapToGlobal(point); - QWindow *focusWindow = qApp->focusWindow(); - moveOnPos(focusWindow, focusWindow->mapFromGlobal(global)); -} - -void tst_menubar::clickOnPos(QObject *window, const QPoint &point) -{ - qApp->sendEvent(window, new QMouseEvent(QEvent::MouseButtonPress, - point, - Qt::LeftButton, - Qt::NoButton, - 0)); - - qApp->sendEvent(window, new QMouseEvent(QEvent::MouseButtonRelease, - point, - Qt::LeftButton, - Qt::NoButton, - 0)); -} - -void tst_menubar::clickOnPos(const QPoint &point) -{ - QPoint global = m_window->mapToGlobal(point); - QWindow *focusWindow = qApp->focusWindow(); - clickOnPos(focusWindow, focusWindow->mapFromGlobal(global)); -} - -void tst_menubar::init() -{ - m_engine = new QQmlApplicationEngine(); - m_engine->load(testFileUrl("WindowWithMenuBar.qml")); - QVERIFY(m_engine->rootObjects().length() > 0); - - m_window = qobject_cast<QQuickWindow*>(m_engine->rootObjects().at(0)); - QVERIFY(m_window); - QVERIFY(QTest::qWaitForWindowExposed(m_window)); - QVERIFY(m_window->contentItem()); - - m_menuBar = m_window->findChildren<QObject*>("menuBar").first(); - QVERIFY(m_menuBar); -} - -void tst_menubar::cleanup() -{ - m_window = 0; - delete m_engine; - m_engine = 0; -} - -void tst_menubar::testClickMenuBarRootMenu() -{ - QObject* fileMenu = m_menuBar->findChildren<QObject*>("fileMenu").first(); - QVERIFY(fileMenu); - QCOMPARE(fileMenu->property("__popupVisible").toBool(), false); - - // Clicking two times should open and close - { - clickOnPos(QPoint(5,5)); - QTest::qWait(WAIT_TIME); - QCOMPARE(fileMenu->property("__popupVisible").toBool(), true); - - clickOnPos(QPoint(5,5)); - QTest::qWait(WAIT_TIME);; - QCOMPARE(fileMenu->property("__popupVisible").toBool(), false); - } - - // Clicking outside should close the menu as well - { - clickOnPos(QPoint(5,5)); - QTest::qWait(WAIT_TIME); - QCOMPARE(fileMenu->property("__popupVisible").toBool(), true); - - clickOnPos(QPoint(300,300)); - QTest::qWait(WAIT_TIME);; - QCOMPARE(fileMenu->property("__popupVisible").toBool(), false); - } -} - -void tst_menubar::testClickMenuBarSubMenu() -{ - QObject *fileMenu = m_menuBar->findChildren<QObject*>("fileMenu").first(); - QVERIFY(fileMenu); - QCOMPARE(fileMenu->property("__popupVisible").toBool(), false); - - clickOnPos(QPoint(5,5)); - QTest::qWait(WAIT_TIME); - QCOMPARE(fileMenu->property("__popupVisible").toBool(), true); - - QQuickItem* fileMenuContentItem = fileMenu->property("__contentItem").value<QQuickItem*>(); - QVERIFY(fileMenuContentItem); - - QObject* actionsSubMenu = fileMenu->findChildren<QObject*>("actionsSubMenu").first(); - QVERIFY(actionsSubMenu); - QCOMPARE(actionsSubMenu->property("visible").toBool(), true); - QCOMPARE(actionsSubMenu->property("__popupVisible").toBool(), false); - - QQuickItem* actionsSubMenuContentItem = actionsSubMenu->property("__contentItem").value<QQuickItem*>(); - QVERIFY(actionsSubMenuContentItem); - - // Click on a submenu should open it - clickOnPos(QPoint(5,25)); - QTest::qWait(WAIT_TIME); - QCOMPARE(actionsSubMenu->property("__popupVisible").toBool(), true); - - // Click on a submenu should not close the popup - clickOnPos(QPoint(5,25)); - QTest::qWait(WAIT_TIME); - QCOMPARE(actionsSubMenu->property("__popupVisible").toBool(), true); - - // Click outside should close the popup - clickOnPos(QPoint(100,100)); - QTest::qWait(WAIT_TIME); - QCOMPARE(actionsSubMenu->property("__popupVisible").toBool(), false); -} - -void tst_menubar::testParentMenuForPopupsOutsideMenuBar() -{ - waitForRendering(m_window); - QCOMPARE(qApp->focusWindow() == m_window, true); - moveOnPos(QPoint(50,50)); - clickOnPos(QPoint(50,50)); - QTest::qWait(500); - QCOMPARE(qApp->focusWindow() == m_window, false); - - QQuickMenuPopupWindow *window = dynamic_cast<QQuickMenuPopupWindow*>(qApp->focusWindow()); - QVERIFY(window); - - QObject *contextMenu = m_window->findChildren<QObject*>("contextMenu").first(); - QVERIFY(contextMenu); - - QCOMPARE(contextMenu, window->menu()); -} - -void tst_menubar::testParentMenuForPopupsInsideMenuBar() -{ - waitForRendering(m_window); - QCOMPARE(qApp->focusWindow() == m_window, true); - moveOnPos(QPoint(5,5)); - clickOnPos(QPoint(5,5)); - QTest::qWait(500); - QCOMPARE(qApp->focusWindow() == m_window, false); - - QQuickMenuPopupWindow *window = dynamic_cast<QQuickMenuPopupWindow*>(qApp->focusWindow()); - QVERIFY(window); - - QObject *fileMenu = m_window->findChildren<QObject*>("fileMenu").first(); - QVERIFY(fileMenu); - - QCOMPARE(fileMenu, window->menu()); -} - - -QTEST_MAIN(tst_menubar) - -#include "tst_menubar.moc" |