aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@qt.io>2018-04-23 14:05:25 +0200
committerLiang Qi <liang.qi@qt.io>2018-04-25 11:50:41 +0000
commitbc93333958e469e2bd79319befb23328a9de38a9 (patch)
treefcc31b6137ca20da1fc5a26f0f459d59c785c6b5 /tests
parent110b7187cef4a920423e860ef0e10f819c283fa2 (diff)
ComboBox: don't block the escape/back key (with fixed test)
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). Note: def92f7 had a broken test (didn't take the popup exit transition into account) and thus, blocked the CI and got rejected in 110b718. Task-number: QTBUG-67684 Change-Id: I46b4731b3006721f3737cf909fbd97331ac6d8ed Reviewed-by: Liang Qi <liang.qi@qt.io> Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/controls/data/tst_combobox.qml80
1 files changed, 80 insertions, 0 deletions
diff --git a/tests/auto/controls/data/tst_combobox.qml b/tests/auto/controls/data/tst_combobox.qml
index 801712be..8e8f9c2f 100644
--- a/tests/auto/controls/data/tst_combobox.qml
+++ b/tests/auto/controls/data/tst_combobox.qml
@@ -1600,4 +1600,84 @@ 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)
+
+ var pressedKeys = 0
+ var releasedKeys = 0
+
+ // popup not visible -> propagates
+ keyPress(data.key)
+ compare(container.pressedKeys, ++pressedKeys)
+ compare(container.lastPressedKey, data.key)
+
+ keyRelease(data.key)
+ compare(container.releasedKeys, ++releasedKeys)
+ 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, pressedKeys)
+
+ keyRelease(data.key)
+ // Popup receives the key release event if it has an exit transition, but
+ // not if it has been immediately closed on press, without a transition.
+ // ### TODO: Should Popup somehow always block the key release event?
+ if (!control.popup.exit)
+ ++releasedKeys
+ compare(container.releasedKeys, releasedKeys)
+
+ tryCompare(control.popup, "visible", false)
+ verify(control.activeFocus)
+
+ // popup not visible -> propagates
+ keyPress(data.key)
+ compare(container.pressedKeys, ++pressedKeys)
+ compare(container.lastPressedKey, data.key)
+
+ keyRelease(data.key)
+ compare(container.releasedKeys, ++releasedKeys)
+ compare(container.lastReleasedKey, data.key)
+ }
}