summaryrefslogtreecommitdiff
path: root/tests/auto/controls/data/tst_combobox.qml
diff options
context:
space:
mode:
authorCaroline Chao <caroline.chao@digia.com>2013-04-09 15:59:41 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-04-22 13:52:33 +0200
commit5e0198535b3a09b15303ca8ab997c81cbe338c92 (patch)
tree8bdae01054a00106a644da51754a63e656d97e75 /tests/auto/controls/data/tst_combobox.qml
parent6254af55e319568b75c304e52801c1a8c3a49ef5 (diff)
downloadqtquickcontrols-5e0198535b3a09b15303ca8ab997c81cbe338c92.tar.gz
Tests: Add autotests for ComboBox
Change-Id: Ie1496463831785d598e611289146a925f1e42af1 Reviewed-by: Gabriel de Dietrich <gabriel.dedietrich@digia.com>
Diffstat (limited to 'tests/auto/controls/data/tst_combobox.qml')
-rw-r--r--tests/auto/controls/data/tst_combobox.qml86
1 files changed, 86 insertions, 0 deletions
diff --git a/tests/auto/controls/data/tst_combobox.qml b/tests/auto/controls/data/tst_combobox.qml
index 5dbf2921..fc135354 100644
--- a/tests/auto/controls/data/tst_combobox.qml
+++ b/tests/auto/controls/data/tst_combobox.qml
@@ -224,5 +224,91 @@ TestCase {
verify(comboBox.activeFocus)
comboBox.destroy()
}
+
+ function test_spaceKey(){
+ if (Qt.platform.os === "mac")
+ skip("When the menu pops up on OS X, it does not return and the test fails after time out")
+
+ var comboBox = Qt.createQmlObject('import QtQuick.Controls 1.0 ; ComboBox { model: 4 }', container, '');
+ var menuIndex = getMenuIndex(comboBox)
+ verify(menuIndex !== -1)
+ comboBox.forceActiveFocus()
+ verify(!comboBox.data[menuIndex].__popupVisible)
+ keyPress(Qt.Key_Space)
+ verify(comboBox.data[menuIndex].__popupVisible)
+
+ // close the menu before destroying the combobox
+ comboBox.data[menuIndex].__closeMenu()
+ verify(!comboBox.data[menuIndex].__popupVisible)
+
+ comboBox.destroy()
+ }
+
+ function test_currentIndexInMenu() {
+ if (Qt.platform.os === "mac")
+ skip("When the menu pops up on OS X, it does not return and the test fails after time out")
+
+ var comboBox = Qt.createQmlObject('import QtQuick.Controls 1.0 ; ComboBox { model: 4 }', container, '');
+ var menuIndex = getMenuIndex(comboBox)
+ comboBox.currentIndex = 2
+ verify(menuIndex !== -1)
+ comboBox.forceActiveFocus()
+ keyPress(Qt.Key_Space)
+ verify(comboBox.data[menuIndex].__popupVisible)
+ compare(comboBox.data[menuIndex].__currentIndex, comboBox.currentIndex)
+ for (var i = 0; i < comboBox.data[menuIndex].items.length; i++)
+ {
+ if ( i !== comboBox.currentIndex)
+ verify(!comboBox.data[menuIndex].items[i].checked)
+ else
+ verify(comboBox.data[menuIndex].items[i].checked)
+ }
+ // close the menu before destroying the combobox
+ comboBox.data[menuIndex].__closeMenu()
+ verify(!comboBox.data[menuIndex].__popupVisible)
+ comboBox.destroy()
+ }
+
+ function test_addRemoveItemsInModel_QTBUG_30379() {
+ var comboBox = Qt.createQmlObject('import QtQuick.Controls 1.0 ; ComboBox {}', testCase, '');
+ comboBox.textRole = "text"
+ comboBox.model = model
+ var menuIndex = getMenuIndex(comboBox)
+ verify(menuIndex !== -1)
+ compare(comboBox.model.count, 3)
+ compare(comboBox.data[menuIndex].items.length, 3)
+ comboBox.model.append({ text: "Tomato", color: "Red" })
+ compare(comboBox.model.count, 4)
+ expectFailContinue('', 'QTBUG-30379')
+ compare(comboBox.data[menuIndex].items.length, 4)
+ comboBox.model.remove(2, 2)
+ compare(comboBox.model.count, 2)
+ expectFailContinue('', 'QTBUG-30379')
+ compare(comboBox.data[menuIndex].items.length, 2)
+ comboBox.destroy()
+ }
+
+ function test_width_QTBUG_30377() {
+ var comboBox = Qt.createQmlObject('import QtQuick.Controls 1.0 ; ComboBox { model: ["A", "BB", "CCCCC"] }', testCase, '');
+ compare(comboBox.currentIndex, 0)
+ var initialWidth = comboBox.width
+ comboBox.currentIndex = 1
+ compare(comboBox.width, initialWidth)
+ comboBox.currentIndex = 2
+ compare(comboBox.width, initialWidth)
+ comboBox.destroy()
+ }
+
+ function getMenuIndex(control) {
+ var index = -1
+ for (var i = 0; i < control.data.length; i++)
+ {
+ if (control.data[i].objectName === 'popup') {
+ index = i
+ break
+ }
+ }
+ return index
+ }
}
}