aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/quick/qquicktextedit
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/quick/qquicktextedit')
-rw-r--r--tests/auto/quick/qquicktextedit/data/keyEventPropagation.qml31
-rw-r--r--tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp43
2 files changed, 74 insertions, 0 deletions
diff --git a/tests/auto/quick/qquicktextedit/data/keyEventPropagation.qml b/tests/auto/quick/qquicktextedit/data/keyEventPropagation.qml
new file mode 100644
index 0000000000..7793827b77
--- /dev/null
+++ b/tests/auto/quick/qquicktextedit/data/keyEventPropagation.qml
@@ -0,0 +1,31 @@
+import QtQuick
+
+FocusScope {
+ Component.onCompleted: edit.forceActiveFocus()
+
+ anchors.fill: parent
+
+ Keys.onPressed: function(event) { keyDown(event.key) }
+ Keys.onReleased: function(event) { keyUp(event.key) }
+ signal keyDown(int key)
+ signal keyUp(int key)
+
+ TextEdit {
+ id: edit
+ anchors.centerIn: parent
+ width: 50
+ height: 50
+ Keys.onPressed: function(event) {
+ event.accepted = event.key == Qt.Key_A || event.key == Qt.Key_Right
+ }
+ Keys.onReleased: function(event) {
+ event.accepted = event.key == Qt.Key_A
+ }
+ Rectangle {
+ anchors.fill: parent
+ anchors.margins: -5
+ color: "transparent"
+ border.width: 1
+ }
+ }
+}
diff --git a/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp b/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp
index ab35e374c7..73723f857c 100644
--- a/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp
+++ b/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp
@@ -232,6 +232,8 @@ private slots:
void inFlickableTouch_data();
void inFlickableTouch();
+ void keyEventPropagation();
+
private:
void simulateKeys(QWindow *window, const QList<Key> &keys);
#if QT_CONFIG(shortcut)
@@ -6002,6 +6004,47 @@ void tst_qquicktextedit::transparentSelectionColor()
QVERIFY(color.green() < 10);
}
+void tst_qquicktextedit::keyEventPropagation()
+{
+ QQuickView view;
+ view.setSource(testFileUrl("keyEventPropagation.qml"));
+ view.show();
+ QVERIFY(QTest::qWaitForWindowExposed(&view));
+ QObject *root = view.rootObject();
+ QVERIFY(root);
+
+ QSignalSpy downSpy(root, SIGNAL(keyDown(int)));
+ QSignalSpy upSpy(root, SIGNAL(keyUp(int)));
+
+ QQuickTextEdit *textEdit = root->findChild<QQuickTextEdit *>();
+ QVERIFY(textEdit->hasActiveFocus());
+ simulateKey(&view, Qt::Key_Back);
+ QCOMPARE(downSpy.count(), 1);
+ QCOMPARE(upSpy.count(), 1);
+ auto downKey = downSpy.takeFirst();
+ auto upKey = upSpy.takeFirst();
+ QCOMPARE(downKey.at(0).toInt(), Qt::Key_Back);
+ QCOMPARE(upKey.at(0).toInt(), Qt::Key_Back);
+
+ simulateKey(&view, Qt::Key_Shift);
+ QCOMPARE(downSpy.count(), 1);
+ QCOMPARE(upSpy.count(), 1);
+ downKey = downSpy.takeFirst();
+ upKey = upSpy.takeFirst();
+ QCOMPARE(downKey.at(0).toInt(), Qt::Key_Shift);
+ QCOMPARE(upKey.at(0).toInt(), Qt::Key_Shift);
+
+ simulateKey(&view, Qt::Key_A);
+ QCOMPARE(downSpy.count(), 0);
+ QCOMPARE(upSpy.count(), 0);
+
+ simulateKey(&view, Qt::Key_Right);
+ QCOMPARE(downSpy.count(), 0);
+ QCOMPARE(upSpy.count(), 1);
+ upKey = upSpy.takeFirst();
+ QCOMPARE(upKey.at(0).toInt(), Qt::Key_Right);
+}
+
QTEST_MAIN(tst_qquicktextedit)
#include "tst_qquicktextedit.moc"