aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@qt.io>2018-02-12 13:07:06 +0100
committerLiang Qi <liang.qi@qt.io>2018-02-12 13:07:06 +0100
commit675c150a28ae9f1ca5f4960caeed522da534f6fc (patch)
treef29de6db23985893ed21c8caaf2fbc1e10aa063b /tests/auto
parente052684db6e0814a6a3397eb21e3ce9f922563da (diff)
parent95b4996a04989aa26c8fba8aaa90b76b7166c2c1 (diff)
Merge remote-tracking branch 'origin/5.10' into 5.11
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/controls/data/tst_abstractbutton.qml221
-rw-r--r--tests/auto/focus/tst_focus.cpp83
-rw-r--r--tests/auto/qquickpopup/tst_qquickpopup.cpp10
3 files changed, 299 insertions, 15 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/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/qquickpopup/tst_qquickpopup.cpp b/tests/auto/qquickpopup/tst_qquickpopup.cpp
index a1e5e246..550655ef 100644
--- a/tests/auto/qquickpopup/tst_qquickpopup.cpp
+++ b/tests/auto/qquickpopup/tst_qquickpopup.cpp
@@ -565,6 +565,16 @@ void tst_QQuickPopup::activeFocusOnClose1()
nonFocusedPopup->close();
QVERIFY(!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());
+ QVERIFY(nonFocusedPopup->hasActiveFocus());
+
+ nonFocusedPopup->close();
+ QVERIFY(!nonFocusedPopup->isVisible());
+ QVERIFY(focusedPopup->hasActiveFocus());
}
void tst_QQuickPopup::activeFocusOnClose2()