diff options
author | Mitch Curtis <mitch.curtis@qt.io> | 2016-05-10 13:58:05 +0200 |
---|---|---|
committer | Mitch Curtis <mitch.curtis@qt.io> | 2016-05-10 12:07:50 +0000 |
commit | f2342bf0646c65512e4df864495cfd3c6c11da65 (patch) | |
tree | 16f5893006bfb9d90fd79e4f4f8f6817c170cb54 /tests/auto/menu | |
parent | f8ebef12d3e9554217f6476d42200d82628816c9 (diff) |
Menu: support dynamically added items in the same way as static ones
Task-number: QTBUG-53274
Change-Id: I172e431cd456b91dee569b510288d0eccbdb4cef
Reviewed-by: J-P Nurmi <jpnurmi@qt.io>
Diffstat (limited to 'tests/auto/menu')
-rw-r--r-- | tests/auto/menu/data/addItem.qml | 61 | ||||
-rw-r--r-- | tests/auto/menu/tst_menu.cpp | 18 |
2 files changed, 79 insertions, 0 deletions
diff --git a/tests/auto/menu/data/addItem.qml b/tests/auto/menu/data/addItem.qml new file mode 100644 index 00000000..7bf07ecb --- /dev/null +++ b/tests/auto/menu/data/addItem.qml @@ -0,0 +1,61 @@ +/**************************************************************************** +** +** Copyright (C) 2016 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:BSD$ +** 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.0 + +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/menu/tst_menu.cpp b/tests/auto/menu/tst_menu.cpp index 98d431f7..0d72814c 100644 --- a/tests/auto/menu/tst_menu.cpp +++ b/tests/auto/menu/tst_menu.cpp @@ -64,6 +64,7 @@ private slots: void mouse(); void contextMenuKeyboard(); void menuButton(); + void addItem(); }; void tst_menu::defaults() @@ -250,6 +251,23 @@ void tst_menu::menuButton() QVERIFY(firstItem->hasActiveFocus()); } +void tst_menu::addItem() +{ + QQuickApplicationHelper helper(this, QLatin1String("addItem.qml")); + QQuickApplicationWindow *window = helper.window; + window->show(); + QVERIFY(QTest::qWaitForWindowActive(window)); + + QQuickMenu *menu = window->property("menu").value<QQuickMenu*>(); + QVERIFY(menu); + menu->open(); + + QQuickItem *menuItem = menu->itemAt(0); + QTest::mouseClick(window, Qt::LeftButton, Qt::NoModifier, + menuItem->mapToScene(QPointF(menuItem->width() / 2, menuItem->height() / 2)).toPoint()); + QVERIFY(!menu->isVisible()); +} + QTEST_MAIN(tst_menu) #include "tst_menu.moc" |