aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@qt.io>2018-04-23 14:05:25 +0200
committerJ-P Nurmi <jpnurmi@qt.io>2018-04-23 19:37:49 +0000
commitdef92f7b657ee9247beffffcb0cadd1eca8be3c6 (patch)
treec804d09050f9ba05a47aa6d27f652261b24f7f5f /tests
parentec0ad4ca9207acbc524a109ffbacb6cbb0fa18a8 (diff)
ComboBox: don't block the escape/back key
Accept Key_Escape or Key_Back only if it actually close the popup. If the popup is not visible, the key is not handled, and the event should therefore propagate (and potentially close the app on Android). Change-Id: Ibdb0cab8e0ac47005c5112f7ca4882288f1f5a17 Task-number: QTBUG-67684 Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/controls/data/tst_combobox.qml71
1 files changed, 71 insertions, 0 deletions
diff --git a/tests/auto/controls/data/tst_combobox.qml b/tests/auto/controls/data/tst_combobox.qml
index 801712be..7f8bc4e8 100644
--- a/tests/auto/controls/data/tst_combobox.qml
+++ b/tests/auto/controls/data/tst_combobox.qml
@@ -1600,4 +1600,75 @@ TestCase {
tryCompare(control.popup, "visible", true)
compare(control.popup.height, control.popup.topPadding + control.popup.bottomPadding)
}
+
+ Component {
+ id: keysMonitor
+ Item {
+ property int pressedKeys: 0
+ property int releasedKeys: 0
+ property int lastPressedKey: 0
+ property int lastReleasedKey: 0
+ property alias comboBox: comboBox
+
+ width: 200
+ height: 200
+
+ Keys.onPressed: { ++pressedKeys; lastPressedKey = event.key }
+ Keys.onReleased: { ++releasedKeys; lastReleasedKey = event.key }
+
+ ComboBox {
+ id: comboBox
+ }
+ }
+ }
+
+ function test_keyClose_data() {
+ return [
+ { tag: "Escape", key: Qt.Key_Escape },
+ { tag: "Back", key: Qt.Key_Back }
+ ]
+ }
+
+ function test_keyClose(data) {
+ var container = createTemporaryObject(keysMonitor, testCase)
+ verify(container)
+
+ var control = comboBox.createObject(container)
+ verify(control)
+
+ control.forceActiveFocus()
+ verify(control.activeFocus)
+
+ // popup not visible -> propagates
+ keyPress(data.key)
+ compare(container.pressedKeys, 1)
+ compare(container.lastPressedKey, data.key)
+
+ keyRelease(data.key)
+ compare(container.releasedKeys, 1)
+ compare(container.lastReleasedKey, data.key)
+
+ verify(control.activeFocus)
+
+ // popup visible -> handled -> does not propagate
+ control.popup.open()
+ tryCompare(control.popup, "opened", true)
+
+ keyPress(data.key)
+ compare(container.pressedKeys, 1)
+
+ keyRelease(data.key)
+ compare(container.releasedKeys, 2) // ### TODO: should Popup block the key release?
+
+ verify(control.activeFocus)
+
+ // popup not visible -> propagates
+ keyPress(data.key)
+ compare(container.pressedKeys, 2)
+ compare(container.lastPressedKey, data.key)
+
+ keyRelease(data.key)
+ compare(container.releasedKeys, 3)
+ compare(container.lastReleasedKey, data.key)
+ }
}