diff options
Diffstat (limited to 'tests/auto')
-rw-r--r-- | tests/auto/controls/data/tst_abstractbutton.qml | 221 | ||||
-rw-r--r-- | tests/auto/controls/data/tst_drawer.qml | 118 | ||||
-rw-r--r-- | tests/auto/controls/data/tst_stackview.qml | 31 | ||||
-rw-r--r-- | tests/auto/focus/tst_focus.cpp | 83 | ||||
-rw-r--r-- | tests/auto/qquickdrawer/tst_qquickdrawer.cpp | 40 | ||||
-rw-r--r-- | tests/auto/qquickpopup/tst_qquickpopup.cpp | 96 |
6 files changed, 409 insertions, 180 deletions
diff --git a/tests/auto/controls/data/tst_abstractbutton.qml b/tests/auto/controls/data/tst_abstractbutton.qml index b266b183..d611a45a 100644 --- a/tests/auto/controls/data/tst_abstractbutton.qml +++ b/tests/auto/controls/data/tst_abstractbutton.qml @@ -392,6 +392,208 @@ TestCase { compare(spy.count, data.resetChanged ? 1 : 0) } + function test_actionIcon_data() { + var data = [] + + // Save duplicating the rows by reusing them with different properties of the same type. + // This means that the first loop will test icon.name and the second one will test icon.source. + var stringPropertyValueSuffixes = [ + { propertyName: "name", valueSuffix: "IconName" }, + { propertyName: "source", valueSuffix: "IconSource" } + ] + + for (var i = 0; i < stringPropertyValueSuffixes.length; ++i) { + var propertyName = stringPropertyValueSuffixes[i].propertyName + var valueSuffix = stringPropertyValueSuffixes[i].valueSuffix + + var buttonPropertyValue = "Button" + valueSuffix + var buttonPropertyValue2 = "Button" + valueSuffix + "2" + var actionPropertyValue = "Action" + valueSuffix + var actionPropertyValue2 = "Action" + valueSuffix + "2" + + data.push({ tag: "implicit " + propertyName, property: propertyName, + initButton: undefined, initAction: actionPropertyValue, + assignExpected: actionPropertyValue, assignChanged: true, + resetExpected: "", resetChanged: true }) + data.push({ tag: "explicit " + propertyName, property: propertyName, + initButton: buttonPropertyValue, initAction: actionPropertyValue, + assignExpected: buttonPropertyValue, assignChanged: false, + resetExpected: buttonPropertyValue, resetChanged: false }) + data.push({ tag: "empty button " + propertyName, property: propertyName, + initButton: "", initAction: actionPropertyValue, + assignExpected: "", assignChanged: false, + resetExpected: "", resetChanged: false }) + data.push({ tag: "empty action " + propertyName, property: propertyName, + initButton: buttonPropertyValue, initAction: "", + assignExpected: buttonPropertyValue, assignChanged: false, + resetExpected: buttonPropertyValue, resetChanged: false }) + data.push({ tag: "empty both " + propertyName, property: propertyName, + initButton: undefined, initAction: "", + assignExpected: "", assignChanged: false, + resetExpected: "", resetChanged: false }) + data.push({ tag: "modify button " + propertyName, property: propertyName, + initButton: undefined, initAction: actionPropertyValue, + assignExpected: actionPropertyValue, assignChanged: true, + modifyButton: buttonPropertyValue2, + modifyButtonExpected: buttonPropertyValue2, modifyButtonChanged: true, + resetExpected: buttonPropertyValue2, resetChanged: false }) + data.push({ tag: "modify implicit action " + propertyName, property: propertyName, + initButton: undefined, initAction: actionPropertyValue, + assignExpected: actionPropertyValue, assignChanged: true, + modifyAction: actionPropertyValue2, + modifyActionExpected: actionPropertyValue2, modifyActionChanged: true, + resetExpected: "", resetChanged: true }) + data.push({ tag: "modify explicit action " + propertyName, property: propertyName, + initButton: buttonPropertyValue, initAction: actionPropertyValue, + assignExpected: buttonPropertyValue, assignChanged: false, + modifyAction: actionPropertyValue2, + modifyActionExpected: buttonPropertyValue, modifyActionChanged: false, + resetExpected: buttonPropertyValue, resetChanged: false }) + } + + var intPropertyNames = [ + "width", + "height", + ] + + for (i = 0; i < intPropertyNames.length; ++i) { + propertyName = intPropertyNames[i] + + buttonPropertyValue = 20 + buttonPropertyValue2 = 21 + actionPropertyValue = 40 + actionPropertyValue2 = 41 + var defaultValue = 0 + + data.push({ tag: "implicit " + propertyName, property: propertyName, + initButton: undefined, initAction: actionPropertyValue, + assignExpected: actionPropertyValue, assignChanged: true, + resetExpected: defaultValue, resetChanged: true }) + data.push({ tag: "explicit " + propertyName, property: propertyName, + initButton: buttonPropertyValue, initAction: actionPropertyValue, + assignExpected: buttonPropertyValue, assignChanged: false, + resetExpected: buttonPropertyValue, resetChanged: false }) + data.push({ tag: "default button " + propertyName, property: propertyName, + initButton: defaultValue, initAction: actionPropertyValue, + assignExpected: defaultValue, assignChanged: false, + resetExpected: defaultValue, resetChanged: false }) + data.push({ tag: "default action " + propertyName, property: propertyName, + initButton: buttonPropertyValue, initAction: defaultValue, + assignExpected: buttonPropertyValue, assignChanged: false, + resetExpected: buttonPropertyValue, resetChanged: false }) + data.push({ tag: "default both " + propertyName, property: propertyName, + initButton: undefined, initAction: defaultValue, + assignExpected: defaultValue, assignChanged: false, + resetExpected: defaultValue, resetChanged: false }) + data.push({ tag: "modify button " + propertyName, property: propertyName, + initButton: undefined, initAction: actionPropertyValue, + assignExpected: actionPropertyValue, assignChanged: true, + modifyButton: buttonPropertyValue2, + modifyButtonExpected: buttonPropertyValue2, modifyButtonChanged: true, + resetExpected: buttonPropertyValue2, resetChanged: false }) + data.push({ tag: "modify implicit action " + propertyName, property: propertyName, + initButton: undefined, initAction: actionPropertyValue, + assignExpected: actionPropertyValue, assignChanged: true, + modifyAction: actionPropertyValue2, + modifyActionExpected: actionPropertyValue2, modifyActionChanged: true, + resetExpected: defaultValue, resetChanged: true }) + data.push({ tag: "modify explicit action " + propertyName, property: propertyName, + initButton: buttonPropertyValue, initAction: actionPropertyValue, + assignExpected: buttonPropertyValue, assignChanged: false, + modifyAction: actionPropertyValue2, + modifyActionExpected: buttonPropertyValue, modifyActionChanged: false, + resetExpected: buttonPropertyValue, resetChanged: false }) + } + + propertyName = "color" + buttonPropertyValue = "#aa0000" + buttonPropertyValue2 = "#ff0000" + actionPropertyValue = "#0000aa" + actionPropertyValue2 = "#0000ff" + defaultValue = "#00000000" + + data.push({ tag: "implicit " + propertyName, property: propertyName, + initButton: undefined, initAction: actionPropertyValue, + assignExpected: actionPropertyValue, assignChanged: true, + resetExpected: defaultValue, resetChanged: true }) + data.push({ tag: "explicit " + propertyName, property: propertyName, + initButton: buttonPropertyValue, initAction: actionPropertyValue, + assignExpected: buttonPropertyValue, assignChanged: false, + resetExpected: buttonPropertyValue, resetChanged: false }) + data.push({ tag: "default button " + propertyName, property: propertyName, + initButton: defaultValue, initAction: actionPropertyValue, + assignExpected: defaultValue, assignChanged: false, + resetExpected: defaultValue, resetChanged: false }) + data.push({ tag: "default action " + propertyName, property: propertyName, + initButton: buttonPropertyValue, initAction: defaultValue, + assignExpected: buttonPropertyValue, assignChanged: false, + resetExpected: buttonPropertyValue, resetChanged: false }) + data.push({ tag: "default both " + propertyName, property: propertyName, + initButton: undefined, initAction: defaultValue, + assignExpected: defaultValue, assignChanged: false, + resetExpected: defaultValue, resetChanged: false }) + data.push({ tag: "modify button " + propertyName, property: propertyName, + initButton: undefined, initAction: actionPropertyValue, + assignExpected: actionPropertyValue, assignChanged: true, + modifyButton: buttonPropertyValue2, + modifyButtonExpected: buttonPropertyValue2, modifyButtonChanged: true, + resetExpected: buttonPropertyValue2, resetChanged: false }) + data.push({ tag: "modify implicit action " + propertyName, property: propertyName, + initButton: undefined, initAction: actionPropertyValue, + assignExpected: actionPropertyValue, assignChanged: true, + modifyAction: actionPropertyValue2, + modifyActionExpected: actionPropertyValue2, modifyActionChanged: true, + resetExpected: defaultValue, resetChanged: true }) + data.push({ tag: "modify explicit action " + propertyName, property: propertyName, + initButton: buttonPropertyValue, initAction: actionPropertyValue, + assignExpected: buttonPropertyValue, assignChanged: false, + modifyAction: actionPropertyValue2, + modifyActionExpected: buttonPropertyValue, modifyActionChanged: false, + resetExpected: buttonPropertyValue, resetChanged: false }) + + return data; + } + + function test_actionIcon(data) { + var control = createTemporaryObject(button, testCase) + verify(control) + control.icon[data.property] = data.initButton + + var act = action.createObject(control) + act.icon[data.property] = data.initAction + + var spy = signalSpy.createObject(control, {target: control, signalName: "iconChanged"}) + verify(spy.valid) + + // assign action + spy.clear() + control.action = act + compare(control.icon[data.property], data.assignExpected) + compare(spy.count, data.assignChanged ? 1 : 0) + + // modify button + if (data.hasOwnProperty("modifyButton")) { + spy.clear() + control.icon[data.property] = data.modifyButton + compare(control.icon[data.property], data.modifyButtonExpected) + compare(spy.count, data.modifyButtonChanged ? 1 : 0) + } + + // modify action + if (data.hasOwnProperty("modifyAction")) { + spy.clear() + act.icon[data.property] = data.modifyAction + compare(control.icon[data.property], data.modifyActionExpected) + compare(spy.count, data.modifyActionChanged ? 1 : 0) + } + + // reset action + spy.clear() + control.action = null + compare(control.icon[data.property], data.resetExpected) + compare(spy.count, data.resetChanged ? 1 : 0) + } + Component { id: actionButton AbstractButton { @@ -412,8 +614,6 @@ TestCase { // initial values compare(control.text, "Default") - compare(control.icon.name, "default") - compare(control.icon.source, "qrc:/icons/default.png") compare(control.checkable, true) compare(control.checked, true) compare(control.enabled, false) @@ -423,14 +623,10 @@ TestCase { // changes via action control.action.text = "Action" - control.action.icon.name = "action" - control.action.icon.source = "qrc:/icons/action.png" control.action.checkable = false control.action.checked = false control.action.enabled = true compare(control.text, "Action") // propagates - compare(control.icon.name, "action") // propagates - compare(control.icon.source, "qrc:/icons/action.png") // propagates compare(control.checkable, false) // propagates compare(control.checked, false) // propagates compare(control.enabled, true) // propagates @@ -438,31 +634,26 @@ TestCase { // changes via button control.text = "Button" - control.icon.name = "button" - control.icon.source = "qrc:/icons/button.png" control.checkable = true control.checked = true control.enabled = false compare(control.text, "Button") - compare(control.icon.name, "button") - compare(control.icon.source, "qrc:/icons/button.png") compare(control.checkable, true) compare(control.checked, true) compare(control.enabled, false) compare(control.action.text, "Action") // does NOT propagate - compare(control.action.icon.name, "action") // does NOT propagate - compare(control.action.icon.source, "qrc:/icons/action.png") // does NOT propagate compare(control.action.checkable, true) // propagates compare(control.action.checked, true) // propagates compare(control.action.enabled, true) // does NOT propagate compare(textSpy.count, 2) - // remove the action so that only the button's text is left + // remove the action so that only the button's properties are left control.action = null compare(control.text, "Button") compare(textSpy.count, 2) - // setting an action while button has text shouldn't cause a change in the button's effective text + // setting an action while button has a particular property set + // shouldn't cause a change in the button's effective property value var secondAction = createTemporaryObject(action, testCase) verify(secondAction) secondAction.text = "SecondAction" @@ -470,7 +661,7 @@ TestCase { compare(control.text, "Button") compare(textSpy.count, 2) - // test setting an action with empty text + // test setting an action whose properties aren't set var thirdAction = createTemporaryObject(action, testCase) verify(thirdAction) control.action = thirdAction diff --git a/tests/auto/controls/data/tst_drawer.qml b/tests/auto/controls/data/tst_drawer.qml deleted file mode 100644 index 5446b969..00000000 --- a/tests/auto/controls/data/tst_drawer.qml +++ /dev/null @@ -1,118 +0,0 @@ -/**************************************************************************** -** -** 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.2 -import QtTest 1.0 -import QtQuick.Controls 2.3 - -TestCase { - id: testCase - width: 400 - height: 400 - visible: true - when: windowShown - name: "Drawer" - - Component { - id: drawer - Drawer { } - } - - function test_defaults() { - var control = createTemporaryObject(drawer, testCase) - compare(control.edge, Qt.LeftEdge) - compare(control.position, 0.0) - compare(control.dragMargin, Qt.styleHints.startDragDistance) - compare(control.parent, Overlay.overlay) - } - - function test_invalidEdge() { - var control = createTemporaryObject(drawer, testCase) - compare(control.edge, Qt.LeftEdge) - - // Test an invalid value - it should warn and ignore it. - ignoreWarning(Qt.resolvedUrl("tst_drawer.qml") + ":65:9: QML Drawer: invalid edge value - valid values are: Qt.TopEdge, Qt.LeftEdge, Qt.RightEdge, Qt.BottomEdge") - control.edge = Drawer.Right - compare(control.edge, Qt.LeftEdge) - } - - Component { - id: rectDrawer - - Drawer { - Rectangle { - width: 200 - height: 400 - color: "steelblue" - } - } - } - - function test_swipeVelocity() { - skip("QTBUG-52003"); - - var control = createTemporaryObject(rectDrawer, testCase) - verify(control.contentItem) - compare(control.edge, Qt.LeftEdge) - compare(control.position, 0.0) - - var dragDistance = Math.max(20, Qt.styleHints.startDragDistance + 5) - var distance = dragDistance * 1.1 - if (distance >= control.width * 0.7) - skip("This test requires a startDragDistance that is less than the opening threshold of the drawer") - - mousePress(control, 0, 0, Qt.LeftButton) - mouseMove(control, distance, 0) - verify(control.position > 0) - tryCompare(control, "position", distance / control.contentItem.width) - mouseRelease(control, distance, 0, Qt.LeftButton) - tryCompare(control, "position", 1.0) - } -} diff --git a/tests/auto/controls/data/tst_stackview.qml b/tests/auto/controls/data/tst_stackview.qml index 6f6497c5..3c0f0273 100644 --- a/tests/auto/controls/data/tst_stackview.qml +++ b/tests/auto/controls/data/tst_stackview.qml @@ -61,7 +61,7 @@ TestCase { name: "StackView" Item { id: item } - TextField { id: textField } + Component { id: textField; TextField { } } Component { id: component; Item { } } Component { @@ -323,22 +323,33 @@ TestCase { compare(item.height, control.height) } - function test_focus() { + function test_focus_data() { + return [ + { tag: "true", focus: true, forceActiveFocus: false }, + { tag: "false", focus: false, forceActiveFocus: false }, + { tag: "forceActiveFocus()", focus: false, forceActiveFocus: true }, + ] + } + + function test_focus(data) { var control = createTemporaryObject(stackView, testCase, {initialItem: item, width: 200, height: 200}) verify(control) - control.forceActiveFocus() - verify(control.activeFocus) + if (data.focus) + control.focus = true + if (data.forceActiveFocus) + control.forceActiveFocus() + compare(control.activeFocus, data.focus || data.forceActiveFocus) - control.push(textField, StackView.Immediate) - compare(control.currentItem, textField) - textField.forceActiveFocus() - verify(textField.activeFocus) + var page = control.push(textField, StackView.Immediate) + verify(page) + compare(control.currentItem, page) + compare(page.activeFocus, control.activeFocus) control.pop(StackView.Immediate) compare(control.currentItem, item) - verify(control.activeFocus) - verify(!textField.activeFocus) + compare(item.activeFocus, data.focus || data.forceActiveFocus) + verify(!page.activeFocus) } function test_find() { diff --git a/tests/auto/focus/tst_focus.cpp b/tests/auto/focus/tst_focus.cpp index 3d4a8875..958b996b 100644 --- a/tests/auto/focus/tst_focus.cpp +++ b/tests/auto/focus/tst_focus.cpp @@ -67,6 +67,9 @@ private slots: void reason(); void visualFocus(); + + void scope_data(); + void scope(); }; void tst_focus::initTestCase() @@ -326,6 +329,86 @@ void tst_focus::visualFocus() QVERIFY(!button->property("showFocus").toBool()); } +void tst_focus::scope_data() +{ + QTest::addColumn<QString>("name"); + + QTest::newRow("Frame") << "Frame"; + QTest::newRow("GroupBox") << "Frame"; + QTest::newRow("Page") << "Page"; + QTest::newRow("Pane") << "Pane"; + QTest::newRow("StackView") << "StackView"; +} + +void tst_focus::scope() +{ + QFETCH(QString, name); + + QQmlEngine engine; + QQmlComponent component(&engine); + component.setData(QString("import QtQuick 2.9; import QtQuick.Controls 2.2; ApplicationWindow { property alias child: child; width: 100; height: 100; %1 { anchors.fill: parent; Item { id: child; width: 10; height: 10 } } }").arg(name).toUtf8(), QUrl()); + + QScopedPointer<QQuickApplicationWindow> window(qobject_cast<QQuickApplicationWindow *>(component.create())); + QVERIFY2(window, qPrintable(component.errorString())); + + QQuickControl *control = qobject_cast<QQuickControl *>(window->contentItem()->childItems().first()); + QVERIFY(control); + + control->setFocusPolicy(Qt::WheelFocus); + control->setAcceptedMouseButtons(Qt::LeftButton); + + QQuickItem *child = window->property("child").value<QQuickItem *>(); + QVERIFY(child); + + window->show(); + window->requestActivate(); + QVERIFY(QTest::qWaitForWindowActive(window.data())); + + struct TouchDeviceDeleter + { + static inline void cleanup(QTouchDevice *device) + { + QWindowSystemInterface::unregisterTouchDevice(device); + delete device; + } + }; + + QScopedPointer<QTouchDevice, TouchDeviceDeleter> device(new QTouchDevice); + device->setType(QTouchDevice::TouchScreen); + QWindowSystemInterface::registerTouchDevice(device.data()); + + child->forceActiveFocus(); + QVERIFY(child->hasActiveFocus()); + QVERIFY(control->hasActiveFocus()); + + // Qt::ClickFocus (mouse) + QTest::mouseClick(window.data(), Qt::LeftButton, Qt::NoModifier, QPoint(control->width() / 2, control->height() / 2)); + QVERIFY(!child->hasActiveFocus()); + QVERIFY(control->hasActiveFocus()); + + // reset + child->forceActiveFocus(); + QVERIFY(child->hasActiveFocus()); + QVERIFY(control->hasActiveFocus()); + + // Qt::ClickFocus (touch) + QTest::touchEvent(window.data(), device.data()).press(0, QPoint(control->width() / 2, control->height() / 2)); + QTest::touchEvent(window.data(), device.data()).release(0, QPoint(control->width() / 2, control->height() / 2)); + QVERIFY(!child->hasActiveFocus()); + QVERIFY(control->hasActiveFocus()); + + // reset + child->forceActiveFocus(); + QVERIFY(child->hasActiveFocus()); + QVERIFY(control->hasActiveFocus()); + + // Qt::WheelFocus + QWheelEvent wheelEvent(QPoint(control->width() / 2, control->height() / 2), 10, Qt::NoButton, Qt::NoModifier); + QGuiApplication::sendEvent(control, &wheelEvent); + QVERIFY(!child->hasActiveFocus()); + QVERIFY(control->hasActiveFocus()); +} + QTEST_MAIN(tst_focus) #include "tst_focus.moc" diff --git a/tests/auto/qquickdrawer/tst_qquickdrawer.cpp b/tests/auto/qquickdrawer/tst_qquickdrawer.cpp index 9f6a556f..60c5b189 100644 --- a/tests/auto/qquickdrawer/tst_qquickdrawer.cpp +++ b/tests/auto/qquickdrawer/tst_qquickdrawer.cpp @@ -38,6 +38,7 @@ #include <QtTest/qsignalspy.h> #include "../shared/util.h" #include "../shared/visualtestutil.h" +#include "../shared/qtest_quickcontrols.h" #include <QtGui/qstylehints.h> #include <QtGui/qtouchdevice.h> @@ -61,6 +62,9 @@ class tst_QQuickDrawer : public QQmlDataTest private slots: void initTestCase(); + void defaults(); + void invalidEdge(); + void visible_data(); void visible(); @@ -126,6 +130,40 @@ void tst_QQuickDrawer::initTestCase() QWindowSystemInterface::registerTouchDevice(touchDevice.data()); } +void tst_QQuickDrawer::defaults() +{ + QQmlEngine engine; + QQmlComponent component(&engine); + component.loadUrl(testFileUrl("window.qml")); + + QScopedPointer<QObject> root(component.create()); + QVERIFY2(!root.isNull(), qPrintable(component.errorString())); + + QQuickDrawer *drawer = root->property("drawer").value<QQuickDrawer *>(); + QVERIFY(drawer); + QCOMPARE(drawer->edge(), Qt::LeftEdge); + QCOMPARE(drawer->position(), 0.0); + QCOMPARE(drawer->dragMargin(), qGuiApp->styleHints()->startDragDistance()); +} + +void tst_QQuickDrawer::invalidEdge() +{ + QQmlEngine engine; + QQmlComponent component(&engine); + component.loadUrl(testFileUrl("window.qml")); + + QScopedPointer<QObject> root(component.create()); + QVERIFY2(!root.isNull(), qPrintable(component.errorString())); + + QQuickDrawer *drawer = root->property("drawer").value<QQuickDrawer *>(); + QVERIFY(drawer); + + // Test an invalid value - it should warn and ignore it. + QTest::ignoreMessage(QtWarningMsg, qUtf8Printable(testFileUrl("window.qml").toString() + ":61:5: QML Drawer: invalid edge value - valid values are: Qt.TopEdge, Qt.LeftEdge, Qt.RightEdge, Qt.BottomEdge")); + drawer->setEdge(static_cast<Qt::Edge>(QQuickDrawer::Right)); + QCOMPARE(drawer->edge(), Qt::LeftEdge); +} + void tst_QQuickDrawer::visible_data() { QTest::addColumn<QString>("source"); @@ -1219,6 +1257,6 @@ void tst_QQuickDrawer::nonModal() QVERIFY(closedSpy.wait()); } -QTEST_MAIN(tst_QQuickDrawer) +QTEST_QUICKCONTROLS_MAIN(tst_QQuickDrawer) #include "tst_qquickdrawer.moc" diff --git a/tests/auto/qquickpopup/tst_qquickpopup.cpp b/tests/auto/qquickpopup/tst_qquickpopup.cpp index a1e5e246..9230116b 100644 --- a/tests/auto/qquickpopup/tst_qquickpopup.cpp +++ b/tests/auto/qquickpopup/tst_qquickpopup.cpp @@ -38,6 +38,7 @@ #include <QtTest/qsignalspy.h> #include "../shared/util.h" #include "../shared/visualtestutil.h" +#include "../shared/qtest_quickcontrols.h" #include <QtGui/qpa/qwindowsysteminterface.h> #include <QtQuickTemplates2/private/qquickapplicationwindow_p.h> @@ -119,7 +120,7 @@ void tst_QQuickPopup::visible() QVERIFY(overlay->childItems().contains(popupItem)); popup->close(); - QVERIFY(!popup->isVisible()); + QTRY_VERIFY(!popup->isVisible()); QVERIFY(!overlay->childItems().contains(popupItem)); popup->setVisible(true); @@ -127,7 +128,7 @@ void tst_QQuickPopup::visible() QVERIFY(overlay->childItems().contains(popupItem)); popup->setVisible(false); - QVERIFY(!popup->isVisible()); + QTRY_VERIFY(!popup->isVisible()); QVERIFY(!overlay->childItems().contains(popupItem)); } @@ -164,7 +165,7 @@ void tst_QQuickPopup::state() QCOMPARE(closedSpy.count(), 0); popup->close(); - QCOMPARE(visibleChangedSpy.count(), 2); + QTRY_COMPARE(visibleChangedSpy.count(), 2); QCOMPARE(aboutToShowSpy.count(), 1); QCOMPARE(aboutToHideSpy.count(), 1); QCOMPARE(openedSpy.count(), 1); @@ -236,6 +237,7 @@ void tst_QQuickPopup::overlay() popup->open(); QVERIFY(popup->isVisible()); QVERIFY(overlay->isVisible()); + QTRY_VERIFY(popup->isOpened()); QTest::mousePress(window, Qt::LeftButton, Qt::NoModifier, QPoint(1, 1)); QCOMPARE(overlayPressedSignal.count(), ++overlayPressCount); @@ -243,16 +245,15 @@ void tst_QQuickPopup::overlay() QCOMPARE(overlayAttachedPressedSignal.count(), overlayPressCount); QCOMPARE(overlayAttachedReleasedSignal.count(), overlayReleaseCount); + QTRY_VERIFY(!popup->isVisible()); + QVERIFY(!overlay->isVisible()); + QTest::mouseRelease(window, Qt::LeftButton, Qt::NoModifier, QPoint(1, 1)); QCOMPARE(overlayPressedSignal.count(), overlayPressCount); QCOMPARE(overlayReleasedSignal.count(), overlayReleaseCount); // no modal-popups open QCOMPARE(overlayAttachedPressedSignal.count(), overlayPressCount); QCOMPARE(overlayAttachedReleasedSignal.count(), overlayReleaseCount); - popup->close(); - QVERIFY(!popup->isVisible()); - QVERIFY(!overlay->isVisible()); - popup->setDim(dim); popup->setModal(modal); popup->setClosePolicy(QQuickPopup::CloseOnReleaseOutside); @@ -261,6 +262,7 @@ void tst_QQuickPopup::overlay() popup->open(); QVERIFY(popup->isVisible()); QVERIFY(overlay->isVisible()); + QTRY_VERIFY(popup->isOpened()); QTest::mousePress(window, Qt::LeftButton, Qt::NoModifier, QPoint(1, 1)); QCOMPARE(overlayPressedSignal.count(), ++overlayPressCount); @@ -274,8 +276,8 @@ void tst_QQuickPopup::overlay() QCOMPARE(overlayAttachedPressedSignal.count(), overlayPressCount); QCOMPARE(overlayAttachedReleasedSignal.count(), overlayReleaseCount); - QVERIFY(!popup->isVisible()); - QCOMPARE(overlay->isVisible(), popup->isVisible()); + QTRY_VERIFY(!popup->isVisible()); + QVERIFY(!overlay->isVisible()); // touch popup->open(); @@ -307,8 +309,8 @@ void tst_QQuickPopup::overlay() QCOMPARE(overlayAttachedPressedSignal.count(), overlayPressCount); QCOMPARE(overlayAttachedReleasedSignal.count(), overlayReleaseCount); - QVERIFY(!popup->isVisible()); - QCOMPARE(overlay->isVisible(), popup->isVisible()); + QTRY_VERIFY(!popup->isVisible()); + QVERIFY(!overlay->isVisible()); // multi-touch popup->open(); @@ -331,7 +333,7 @@ void tst_QQuickPopup::overlay() QCOMPARE(overlayReleasedSignal.count(), overlayReleaseCount); QTest::touchEvent(window, device.data()).release(0, button->mapToScene(QPointF(1, 1)).toPoint()).stationary(1); - QVERIFY(!popup->isVisible()); + QTRY_VERIFY(!popup->isVisible()); QVERIFY(!overlay->isVisible()); QVERIFY(!button->isPressed()); QCOMPARE(overlayPressedSignal.count(), overlayPressCount); @@ -378,12 +380,12 @@ void tst_QQuickPopup::zOrder() QVERIFY(popup->isVisible()); QTest::mouseClick(window, Qt::LeftButton, Qt::NoModifier, QPoint(1, 1)); - QVERIFY(!popup2->isVisible()); + QTRY_VERIFY(!popup2->isVisible()); QVERIFY(popup->isVisible()); QTest::mouseClick(window, Qt::LeftButton, Qt::NoModifier, QPoint(1, 1)); QVERIFY(!popup2->isVisible()); - QVERIFY(!popup->isVisible()); + QTRY_VERIFY(!popup->isVisible()); } void tst_QQuickPopup::windowChange() @@ -483,49 +485,55 @@ void tst_QQuickPopup::closePolicy() popup->open(); QVERIFY(popup->isVisible()); + QTRY_VERIFY(popup->isOpened()); // press outside popup and its parent QTest::mousePress(window, Qt::LeftButton, Qt::NoModifier, QPoint(1, 1)); if (closePolicy.testFlag(QQuickPopup::CloseOnPressOutside) || closePolicy.testFlag(QQuickPopup::CloseOnPressOutsideParent)) - QVERIFY(!popup->isVisible()); + QTRY_VERIFY(!popup->isVisible()); else QVERIFY(popup->isVisible()); popup->open(); QVERIFY(popup->isVisible()); + QTRY_VERIFY(popup->isOpened()); // release outside popup and its parent QTest::mouseRelease(window, Qt::LeftButton, Qt::NoModifier, QPoint(1, 1)); if (closePolicy.testFlag(QQuickPopup::CloseOnReleaseOutside)) - QVERIFY(!popup->isVisible()); + QTRY_VERIFY(!popup->isVisible()); else QVERIFY(popup->isVisible()); popup->open(); QVERIFY(popup->isVisible()); + QTRY_VERIFY(popup->isOpened()); // press outside popup but inside its parent - QTest::mousePress(window, Qt::LeftButton, Qt::NoModifier, QPoint(button->x(), button->y())); + QTest::mousePress(window, Qt::LeftButton, Qt::NoModifier, QPoint(button->x() + 1, button->y() + 1)); if (closePolicy.testFlag(QQuickPopup::CloseOnPressOutside) && !closePolicy.testFlag(QQuickPopup::CloseOnPressOutsideParent)) - QVERIFY(!popup->isVisible()); + QTRY_VERIFY(!popup->isVisible()); else QVERIFY(popup->isVisible()); popup->open(); QVERIFY(popup->isVisible()); + QTRY_VERIFY(popup->isOpened()); // release outside popup but inside its parent - QTest::mouseRelease(window, Qt::LeftButton, Qt::NoModifier, QPoint(button->x(), button->y())); + QTest::mouseRelease(window, Qt::LeftButton, Qt::NoModifier, QPoint(button->x() + 1, button->y() + 1)); if (closePolicy.testFlag(QQuickPopup::CloseOnReleaseOutside) && !closePolicy.testFlag(QQuickPopup::CloseOnReleaseOutsideParent)) - QVERIFY(!popup->isVisible()); + QTRY_VERIFY(!popup->isVisible()); else QVERIFY(popup->isVisible()); popup->open(); QVERIFY(popup->isVisible()); + QTRY_VERIFY(popup->isOpened()); // press inside and release outside - QTest::mousePress(window, Qt::LeftButton, Qt::NoModifier, QPoint(button->x() + popup->x(), button->y() + popup->y())); + QTest::mousePress(window, Qt::LeftButton, Qt::NoModifier, QPoint(button->x() + popup->x() + 1, + button->y() + popup->y() + 1)); QVERIFY(popup->isVisible()); QTest::mouseRelease(window, Qt::LeftButton, Qt::NoModifier, QPoint(1, 1)); QVERIFY(popup->isVisible()); @@ -533,7 +541,7 @@ void tst_QQuickPopup::closePolicy() // escape QTest::keyClick(window, Qt::Key_Escape); if (closePolicy.testFlag(QQuickPopup::CloseOnEscape)) - QVERIFY(!popup->isVisible()); + QTRY_VERIFY(!popup->isVisible()); else QVERIFY(popup->isVisible()); } @@ -556,14 +564,27 @@ void tst_QQuickPopup::activeFocusOnClose1() focusedPopup->open(); QVERIFY(focusedPopup->isVisible()); + QTRY_VERIFY(focusedPopup->isOpened()); QVERIFY(focusedPopup->hasActiveFocus()); nonFocusedPopup->open(); QVERIFY(nonFocusedPopup->isVisible()); + QTRY_VERIFY(nonFocusedPopup->isOpened()); QVERIFY(focusedPopup->hasActiveFocus()); nonFocusedPopup->close(); - QVERIFY(!nonFocusedPopup->isVisible()); + QTRY_VERIFY(!nonFocusedPopup->isVisible()); + QVERIFY(focusedPopup->hasActiveFocus()); + + // QTBUG-66113: force active focus on a popup that did not request focus + nonFocusedPopup->open(); + nonFocusedPopup->forceActiveFocus(); + QVERIFY(nonFocusedPopup->isVisible()); + QTRY_VERIFY(nonFocusedPopup->isOpened()); + QVERIFY(nonFocusedPopup->hasActiveFocus()); + + nonFocusedPopup->close(); + QTRY_VERIFY(!nonFocusedPopup->isVisible()); QVERIFY(focusedPopup->hasActiveFocus()); } @@ -589,16 +610,18 @@ void tst_QQuickPopup::activeFocusOnClose2() popup1->open(); QVERIFY(popup1->isVisible()); + QTRY_VERIFY(popup1->isOpened()); QVERIFY(popup1->hasActiveFocus()); popup2->open(); QVERIFY(popup2->isVisible()); + QTRY_VERIFY(popup2->isOpened()); QVERIFY(popup2->hasActiveFocus()); // Causes popup1.contentItem.forceActiveFocus() to be called, then closes popup2. QTest::mouseClick(window, Qt::LeftButton, Qt::NoModifier, closePopup2Button->mapToScene(QPointF(closePopup2Button->width() / 2, closePopup2Button->height() / 2)).toPoint()); - QVERIFY(!popup2->isVisible()); + QTRY_VERIFY(!popup2->isVisible()); QVERIFY(popup1->hasActiveFocus()); } @@ -684,7 +707,7 @@ void tst_QQuickPopup::hover() QVERIFY(!childButton->isHovered()); // hover the child button in a popup - QTest::mouseMove(window, QPoint(2, 2)); + QTest::mouseMove(window, QPoint(popup->x() + popup->width() / 2, popup->y() + popup->height() / 2)); QVERIFY(!parentButton->isHovered()); QVERIFY(childButton->isHovered()); @@ -834,35 +857,35 @@ void tst_QQuickPopup::grabber() QVERIFY(combo); menu->open(); - QCOMPARE(menu->isVisible(), true); + QTRY_COMPARE(menu->isOpened(), true); QCOMPARE(popup->isVisible(), false); QCOMPARE(combo->isVisible(), false); // click a menu item to open the popup QTest::mouseClick(window, Qt::LeftButton, Qt::NoModifier, QPoint(menu->width() / 2, menu->height() / 2)); - QCOMPARE(menu->isVisible(), false); - QCOMPARE(popup->isVisible(), true); + QTRY_COMPARE(menu->isVisible(), false); + QTRY_COMPARE(popup->isOpened(), true); QCOMPARE(combo->isVisible(), false); combo->open(); QCOMPARE(menu->isVisible(), false); QCOMPARE(popup->isVisible(), true); - QCOMPARE(combo->isVisible(), true); + QTRY_COMPARE(combo->isOpened(), true); // click outside to close both the combo popup and the parent popup QTest::mouseClick(window, Qt::LeftButton, Qt::NoModifier, QPoint(window->width() - 1, window->height() - 1)); QCOMPARE(menu->isVisible(), false); - QCOMPARE(popup->isVisible(), false); - QCOMPARE(combo->isVisible(), false); + QTRY_COMPARE(popup->isVisible(), false); + QTRY_COMPARE(combo->isVisible(), false); menu->open(); - QCOMPARE(menu->isVisible(), true); + QTRY_COMPARE(menu->isOpened(), true); QCOMPARE(popup->isVisible(), false); QCOMPARE(combo->isVisible(), false); // click outside the menu to close it (QTBUG-56697) QTest::mouseClick(window, Qt::LeftButton, Qt::NoModifier, QPoint(window->width() - 1, window->height() - 1)); - QCOMPARE(menu->isVisible(), false); + QTRY_COMPARE(menu->isVisible(), false); QCOMPARE(popup->isVisible(), false); QCOMPARE(combo->isVisible(), false); } @@ -881,17 +904,18 @@ void tst_QQuickPopup::cursorShape() popup->open(); QVERIFY(popup->isVisible()); + QTRY_VERIFY(popup->isOpened()); QQuickItem *textField = helper.appWindow->property("textField").value<QQuickItem*>(); QVERIFY(textField); // Move the mouse over the text field. - const QPoint textFieldPos(popup->x() - 10, popup->y() + popup->height() / 2); + const QPoint textFieldPos(popup->x() - 10, textField->height() / 2); QTest::mouseMove(window, textFieldPos); QCOMPARE(window->cursor().shape(), textField->cursor().shape()); // Move the mouse over the popup where it overlaps with the text field. - const QPoint textFieldOverlapPos(popup->x() + 10, popup->y() + popup->height() / 2); + const QPoint textFieldOverlapPos(popup->x() + 10, textField->height() / 2); QTest::mouseMove(window, textFieldOverlapPos); QCOMPARE(window->cursor().shape(), popup->popupItem()->cursor().shape()); @@ -1036,6 +1060,6 @@ void tst_QQuickPopup::orientation() QCOMPARE(popup->popupItem()->position(), position); } -QTEST_MAIN(tst_QQuickPopup) +QTEST_QUICKCONTROLS_MAIN(tst_QQuickPopup) #include "tst_qquickpopup.moc" |