summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorAlberto Mardegan <mardy@users.sourceforge.net>2016-02-15 00:04:14 +0300
committerAlberto Mardegan <mardy@users.sourceforge.net>2018-02-12 19:04:27 +0000
commit8889eaacc45b9a5e35e9c3182dece9f46560b2de (patch)
treef799afe28dccdb35fb929c14d32c6a3a899fe7e8 /tests
parent4459886e3f949821425dd5fd9fc9da0416d0ffc9 (diff)
ComboBox: guarantee index consistency when emitting activated()
The "triggered" signal from the ComboBox menu items is handled twice: once in ComboBox.qml, and once in QQuickMenuItem. The function of the latter is to update the parent QQuickMenu's selected index. With the current change we guarantee that the selected index (that is exposed as "currentIndex" in the public API) is updated only once, before any activated() signal is emitted. This also allows the handler of the activated() signal to update currentIndex at will, without running the risk of having it overwritten again by the ComboBox internal code. Task-number: QTBUG-51113 Task-number: QTBUG-43050 Change-Id: Ibfe12752d02eb4c9e2bf9a73ee8b3ab0ca8d7eaa Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io> Reviewed-by: Frederik Gladhorn <frederik.gladhorn@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/controls/data/tst_combobox.qml55
1 files changed, 55 insertions, 0 deletions
diff --git a/tests/auto/controls/data/tst_combobox.qml b/tests/auto/controls/data/tst_combobox.qml
index 415d3ad30..bccac8d23 100644
--- a/tests/auto/controls/data/tst_combobox.qml
+++ b/tests/auto/controls/data/tst_combobox.qml
@@ -418,6 +418,61 @@ TestCase {
comboBox.destroy()
}
+ function test_activated_index_QTBUG_43050(){
+ if (Qt.platform.os === "osx")
+ skip("When the menu pops up on OS X, it does not return and the test fails after time out")
+ if (Qt.platform.os === "windows")
+ skip("Test randomly fails under Windows")
+
+ var comboBox = Qt.createQmlObject('import QtQuick.Controls 1.2; \
+ ComboBox { \
+ property bool indexWasUpdated: false; \
+ model: 4; \
+ onActivated: indexWasUpdated = (index === currentIndex); \
+ }', container, '');
+ var menuIndex = getMenuIndex(comboBox)
+ verify(menuIndex !== -1)
+ comboBox.forceActiveFocus()
+ verify(!comboBox.data[menuIndex].__popupVisible)
+ keyPress(Qt.Key_Space)
+ verify(comboBox.data[menuIndex].__popupVisible)
+
+ waitForRendering(comboBox)
+ keyPress(Qt.Key_Down)
+ keyPress(Qt.Key_Down)
+ verify(!comboBox.indexWasUpdated)
+ keyPress(Qt.Key_Enter)
+ verify(comboBox.indexWasUpdated)
+
+ comboBox.destroy()
+ }
+
+ function test_update_index_on_activated_QTBUG_51113(){
+ if (Qt.platform.os === "osx")
+ skip("When the menu pops up on OS X, it does not return and the test fails after time out")
+ if (Qt.platform.os === "windows")
+ skip("Test randomly fails under Windows")
+
+ var comboBox = Qt.createQmlObject('import QtQuick.Controls 1.2; \
+ ComboBox { \
+ model: 4; \
+ onActivated: if (index == 1) currentIndex = 3; \
+ }', container, '');
+ var menuIndex = getMenuIndex(comboBox)
+ verify(menuIndex !== -1)
+ comboBox.forceActiveFocus()
+ verify(!comboBox.data[menuIndex].__popupVisible)
+ keyPress(Qt.Key_Space)
+ verify(comboBox.data[menuIndex].__popupVisible)
+
+ waitForRendering(comboBox)
+ keyPress(Qt.Key_Down)
+ keyPress(Qt.Key_Enter)
+ compare(comboBox.currentIndex, 3)
+
+ comboBox.destroy()
+ }
+
function test_activeFocusOnTab() {
if (Qt.styleHints.tabFocusBehavior != Qt.TabFocusAllControls)
skip("This function doesn't support NOT iterating all.")