diff options
Diffstat (limited to 'tests/auto/controls/data/tst_combobox.qml')
-rw-r--r-- | tests/auto/controls/data/tst_combobox.qml | 447 |
1 files changed, 356 insertions, 91 deletions
diff --git a/tests/auto/controls/data/tst_combobox.qml b/tests/auto/controls/data/tst_combobox.qml index 0a2c3101..607de2e8 100644 --- a/tests/auto/controls/data/tst_combobox.qml +++ b/tests/auto/controls/data/tst_combobox.qml @@ -39,35 +39,30 @@ ****************************************************************************/ import QtQuick 2.2 +import QtQuick.Window 2.2 import QtTest 1.0 -import Qt.labs.controls 1.0 +import QtQuick.Controls 2.0 TestCase { id: testCase width: 200 height: 200 + visible: true + when: windowShown name: "ComboBox" - ApplicationWindow { - id: window - visible: true - width: 400 - height: 400 - font.pixelSize: 25 - } - - SignalSpy { - id: activatedSpy - signalName: "activated" + Component { + id: signalSpy + SignalSpy { } } - SignalSpy { - id: highlightedSpy - signalName: "highlighted" + Component { + id: comboBox + ComboBox { } } Component { - id: comboBox + id: emptyBox ComboBox { delegate: ItemDelegate { width: popup.width @@ -75,29 +70,8 @@ TestCase { } } - function initTestCase() { - window.requestActivate() - tryCompare(window, "active", true) - } - - function init() { - verify(!activatedSpy.target) - compare(activatedSpy.count, 0) - - verify(!highlightedSpy.target) - compare(highlightedSpy.count, 0) - } - - function cleanup() { - activatedSpy.target = null - activatedSpy.clear() - - highlightedSpy.target = null - highlightedSpy.clear() - } - function test_defaults() { - var control = comboBox.createObject(window.contentItem) + var control = comboBox.createObject(testCase) verify(control) compare(control.count, 0) @@ -107,13 +81,14 @@ TestCase { compare(control.highlightedIndex, -1) compare(control.currentText, "") verify(control.delegate) + verify(control.indicator) verify(control.popup) control.destroy() } function test_array() { - var control = comboBox.createObject(window.contentItem) + var control = comboBox.createObject(testCase) verify(control) var items = [ "Banana", "Apple", "Coconut" ] @@ -139,7 +114,7 @@ TestCase { } function test_objects() { - var control = comboBox.createObject(window.contentItem) + var control = emptyBox.createObject(testCase) verify(control) var items = [ @@ -169,7 +144,7 @@ TestCase { } function test_number() { - var control = comboBox.createObject(window.contentItem) + var control = comboBox.createObject(testCase) verify(control) control.model = 10 @@ -202,7 +177,7 @@ TestCase { } function test_listModel() { - var control = comboBox.createObject(window.contentItem) + var control = comboBox.createObject(testCase) verify(control) control.model = listmodel @@ -246,7 +221,7 @@ TestCase { } function test_textRole(data) { - var control = comboBox.createObject(window.contentItem) + var control = emptyBox.createObject(testCase) verify(control) control.model = data.model @@ -274,7 +249,7 @@ TestCase { } function test_textAt() { - var control = comboBox.createObject(window.contentItem) + var control = comboBox.createObject(testCase) verify(control) control.model = ["Apple", "Orange", "Banana"] @@ -316,7 +291,7 @@ TestCase { } function test_find(data) { - var control = comboBox.createObject(window.contentItem) + var control = comboBox.createObject(testCase) verify(control) control.model = ["Banana", "banana", "Coconut", "Apple", "Cocomuffin"] @@ -326,14 +301,15 @@ TestCase { control.destroy() } + function test_arrowKeys() { - var control = comboBox.createObject(window.contentItem, {model: 3}) + var control = comboBox.createObject(testCase, {model: 3}) verify(control) - activatedSpy.target = control + var activatedSpy = signalSpy.createObject(control, {target: control, signalName: "activated"}) verify(activatedSpy.valid) - highlightedSpy.target = control + var highlightedSpy = signalSpy.createObject(control, {target: control, signalName: "highlighted"}) verify(highlightedSpy.valid) waitForRendering(control) @@ -450,29 +426,30 @@ TestCase { keyClick(Qt.Key_Space) compare(control.currentIndex, 1) - compare(control.highlightedIndex, -1) + tryCompare(control, "highlightedIndex", -1) control.destroy() } - function test_keys_data() { + function test_keys_space_enter_escape_data() { return [ { tag: "space-space", key1: Qt.Key_Space, key2: Qt.Key_Space, showPopup: true, showPress: true, hidePopup: true, hidePress: true }, { tag: "space-enter", key1: Qt.Key_Space, key2: Qt.Key_Enter, showPopup: true, showPress: true, hidePopup: true, hidePress: true }, { tag: "space-return", key1: Qt.Key_Space, key2: Qt.Key_Return, showPopup: true, showPress: true, hidePopup: true, hidePress: true }, { tag: "space-escape", key1: Qt.Key_Space, key2: Qt.Key_Escape, showPopup: true, showPress: true, hidePopup: true, hidePress: false }, { tag: "space-0", key1: Qt.Key_Space, key2: Qt.Key_0, showPopup: true, showPress: true, hidePopup: false, hidePress: false }, - { tag: "enter-enter", key1: Qt.Key_Enter, key2: Qt.Key_Enter, showPopup: false, showPress: false, hidePopup: true, hidePress: false }, { tag: "return-return", key1: Qt.Key_Return, key2: Qt.Key_Return, showPopup: false, showPress: false, hidePopup: true, hidePress: false }, - { tag: "escape-escape", key1: Qt.Key_Escape, key2: Qt.Key_Escape, showPopup: false, showPress: false, hidePopup: true, hidePress: false }, + { tag: "escape-escape", key1: Qt.Key_Escape, key2: Qt.Key_Escape, showPopup: false, showPress: false, hidePopup: true, hidePress: false } ] } - function test_keys(data) { - var control = comboBox.createObject(window.contentItem, {model: 3}) + function test_keys_space_enter_escape(data) { + var control = comboBox.createObject(testCase, {model: 3}) verify(control) + waitForRendering(control) + control.forceActiveFocus() verify(control.activeFocus) @@ -490,7 +467,6 @@ TestCase { // hide popup keyPress(data.key2) compare(control.pressed, data.hidePress) - compare(control.popup.visible, data.showPopup) keyRelease(data.key2) compare(control.pressed, false) tryCompare(control.popup, "visible", !data.hidePopup) @@ -498,8 +474,164 @@ TestCase { control.destroy() } + function test_keys_home_end() { + var control = comboBox.createObject(testCase, {model: 5}) + verify(control) + + control.forceActiveFocus() + verify(control.activeFocus) + compare(control.currentIndex, 0) + compare(control.highlightedIndex, -1) + + var activatedCount = 0 + var activatedSpy = signalSpy.createObject(control, {target: control, signalName: "activated"}) + verify(activatedSpy.valid) + + var highlightedCount = 0 + var highlightedSpy = signalSpy.createObject(control, {target: control, signalName: "highlighted"}) + verify(highlightedSpy.valid) + + var currentIndexCount = 0 + var currentIndexSpy = signalSpy.createObject(control, {target: control, signalName: "currentIndexChanged"}) + verify(currentIndexSpy.valid) + + var highlightedIndexCount = 0 + var highlightedIndexSpy = signalSpy.createObject(control, {target: control, signalName: "highlightedIndexChanged"}) + verify(highlightedIndexSpy.valid) + + // end (popup closed) + keyClick(Qt.Key_End) + compare(control.currentIndex, 4) + compare(currentIndexSpy.count, ++currentIndexCount) + + compare(control.highlightedIndex, -1) + compare(highlightedIndexSpy.count, highlightedIndexCount) + + compare(activatedSpy.count, ++activatedCount) + compare(activatedSpy.signalArguments[activatedCount-1][0], 4) + + compare(highlightedSpy.count, highlightedCount) + + // repeat (no changes/signals) + keyClick(Qt.Key_End) + compare(currentIndexSpy.count, currentIndexCount) + compare(highlightedIndexSpy.count, highlightedIndexCount) + compare(activatedSpy.count, activatedCount) + compare(highlightedSpy.count, highlightedCount) + + // home (popup closed) + keyClick(Qt.Key_Home) + compare(control.currentIndex, 0) + compare(currentIndexSpy.count, ++currentIndexCount) + + compare(control.highlightedIndex, -1) + compare(highlightedIndexSpy.count, highlightedIndexCount) + + compare(activatedSpy.count, ++activatedCount) + compare(activatedSpy.signalArguments[activatedCount-1][0], 0) + + compare(highlightedSpy.count, highlightedCount) + + // repeat (no changes/signals) + keyClick(Qt.Key_Home) + compare(currentIndexSpy.count, currentIndexCount) + compare(highlightedIndexSpy.count, highlightedIndexCount) + compare(activatedSpy.count, activatedCount) + compare(highlightedSpy.count, highlightedCount) + + control.popup.open() + compare(control.highlightedIndex, 0) + compare(highlightedIndexSpy.count, ++highlightedIndexCount) + compare(highlightedSpy.count, highlightedCount) + + // end (popup open) + keyClick(Qt.Key_End) + compare(control.currentIndex, 0) + compare(currentIndexSpy.count, currentIndexCount) + + compare(control.highlightedIndex, 4) + compare(highlightedIndexSpy.count, ++highlightedIndexCount) + + compare(activatedSpy.count, activatedCount) + + compare(highlightedSpy.count, ++highlightedCount) + compare(highlightedSpy.signalArguments[highlightedCount-1][0], 4) + + // repeat (no changes/signals) + keyClick(Qt.Key_End) + compare(currentIndexSpy.count, currentIndexCount) + compare(highlightedIndexSpy.count, highlightedIndexCount) + compare(activatedSpy.count, activatedCount) + compare(highlightedSpy.count, highlightedCount) + + // home (popup open) + keyClick(Qt.Key_Home) + compare(control.currentIndex, 0) + compare(currentIndexSpy.count, currentIndexCount) + + compare(control.highlightedIndex, 0) + compare(highlightedIndexSpy.count, ++highlightedIndexCount) + + compare(activatedSpy.count, activatedCount) + + compare(highlightedSpy.count, ++highlightedCount) + compare(highlightedSpy.signalArguments[highlightedCount-1][0], 0) + + // repeat (no changes/signals) + keyClick(Qt.Key_Home) + compare(currentIndexSpy.count, currentIndexCount) + compare(highlightedIndexSpy.count, highlightedIndexCount) + compare(activatedSpy.count, activatedCount) + compare(highlightedSpy.count, highlightedCount) + + control.destroy() + } + + function test_keySearch() { + var control = comboBox.createObject(testCase, {model: ["Banana", "Coco", "Coconut", "Apple", "Cocomuffin"]}) + verify(control) + + control.forceActiveFocus() + verify(control.activeFocus) + + compare(control.currentIndex, 0) + compare(control.currentText, "Banana") + + keyPress(Qt.Key_C) + compare(control.currentIndex, 1) + compare(control.currentText, "Coco") + + // no match + keyPress(Qt.Key_N) + compare(control.currentIndex, 1) + compare(control.currentText, "Coco") + + keyPress(Qt.Key_C) + compare(control.currentIndex, 2) + compare(control.currentText, "Coconut") + + keyPress(Qt.Key_C) + compare(control.currentIndex, 4) + compare(control.currentText, "Cocomuffin") + + // wrap + keyPress(Qt.Key_C) + compare(control.currentIndex, 1) + compare(control.currentText, "Coco") + + keyPress(Qt.Key_A) + compare(control.currentIndex, 3) + compare(control.currentText, "Apple") + + keyPress(Qt.Key_B) + compare(control.currentIndex, 0) + compare(control.currentText, "Banana") + + control.destroy() + } + function test_popup() { - var control = comboBox.createObject(window.contentItem, {model: 3}) + var control = comboBox.createObject(testCase, {model: 3}) verify(control) // show below @@ -517,7 +649,7 @@ TestCase { tryCompare(control.popup, "visible", false) // show above - control.y = window.height - control.height + control.y = control.Window.height - control.height mousePress(control) compare(control.pressed, true) compare(control.popup.visible, false) @@ -526,17 +658,25 @@ TestCase { compare(control.popup.visible, true) verify(control.popup.contentItem.y < control.y) + // follow the control outside the horizontal window bounds + control.x = -control.width / 2 + compare(control.x, -control.width / 2) + compare(control.popup.contentItem.parent.x, -control.width / 2) + control.x = testCase.width - control.width / 2 + compare(control.x, testCase.width - control.width / 2) + compare(control.popup.contentItem.parent.x, testCase.width - control.width / 2) + control.destroy() } function test_mouse() { - var control = comboBox.createObject(window.contentItem, {model: 3}) + var control = comboBox.createObject(testCase, {model: 3}) verify(control) - activatedSpy.target = control + var activatedSpy = signalSpy.createObject(control, {target: control, signalName: "activated"}) verify(activatedSpy.valid) - highlightedSpy.target = control + var highlightedSpy = signalSpy.createObject(control, {target: control, signalName: "highlighted"}) verify(highlightedSpy.valid) mouseClick(control) @@ -573,17 +713,18 @@ TestCase { } function test_focus() { - var control = comboBox.createObject(window.contentItem, {model: 3}) + var control = comboBox.createObject(testCase, {model: 3}) verify(control) + waitForRendering(control) + // click - gain focus - show popup mouseClick(control) verify(control.activeFocus) compare(control.popup.visible, true) // lose focus - hide popup - window.contentItem.forceActiveFocus() - verify(window.contentItem.activeFocus) + control.focus = false verify(!control.activeFocus) tryCompare(control.popup, "visible", false) @@ -648,11 +789,9 @@ TestCase { width: _combobox.width text: _combobox.textRole ? (Array.isArray(_combobox.model) ? modelData[_combobox.textRole] : model[_combobox.textRole]) : modelData objectName: "delegate" - checkable: true autoExclusive: true checked: _combobox.currentIndex === index highlighted: _combobox.highlightedIndex === index - pressed: highlighted && _combobox.pressed } } } @@ -672,52 +811,72 @@ TestCase { } function test_font() { // QTBUG_50984, QTBUG-51696 - var control = component.createObject(window.contentItem) + var control = component.createObject(testCase) verify(control) verify(control.button) verify(control.combobox) waitForRendering(control) - control.forceActiveFocus() - verify(control.activeFocus) - compare(control.font.pixelSize, 30) compare(control.button.font.pixelSize, 20) compare(control.combobox.font.pixelSize, 30) - verify(control.combobox.popup) - var popup = control.combobox.popup - popup.open() +// verify(control.combobox.popup) +// var popup = control.combobox.popup +// popup.open() - verify(popup.contentItem) +// verify(popup.contentItem) - var listview = popup.contentItem - verify(listview.contentItem) - waitForRendering(listview) +// var listview = popup.contentItem +// verify(listview.contentItem) +// waitForRendering(listview) - var idx1 = getChild(listview.contentItem, "delegate", -1) - compare(listview.contentItem.children[idx1].font.pixelSize, 25) - var idx2 = getChild(listview.contentItem, "delegate", idx1) - compare(listview.contentItem.children[idx2].font.pixelSize, 25) +// var idx1 = getChild(listview.contentItem, "delegate", -1) +// compare(listview.contentItem.children[idx1].font.pixelSize, 25) +// var idx2 = getChild(listview.contentItem, "delegate", idx1) +// compare(listview.contentItem.children[idx2].font.pixelSize, 25) - compare(listview.contentItem.children[idx1].font.pixelSize, 25) - compare(listview.contentItem.children[idx2].font.pixelSize, 25) +// compare(listview.contentItem.children[idx1].font.pixelSize, 25) +// compare(listview.contentItem.children[idx2].font.pixelSize, 25) control.font.pixelSize = control.font.pixelSize + 10 compare(control.combobox.font.pixelSize, 40) - waitForRendering(listview) - compare(listview.contentItem.children[idx1].font.pixelSize, 25) - compare(listview.contentItem.children[idx2].font.pixelSize, 25) +// waitForRendering(listview) +// compare(listview.contentItem.children[idx1].font.pixelSize, 25) +// compare(listview.contentItem.children[idx2].font.pixelSize, 25) control.combobox.font.pixelSize = control.combobox.font.pixelSize + 5 compare(control.combobox.font.pixelSize, 45) - waitForRendering(listview) +// waitForRendering(listview) + +// idx1 = getChild(listview.contentItem, "delegate", -1) +// compare(listview.contentItem.children[idx1].font.pixelSize, 25) +// idx2 = getChild(listview.contentItem, "delegate", idx1) +// compare(listview.contentItem.children[idx2].font.pixelSize, 25) + + control.destroy() + } + + function test_wheel() { + var control = comboBox.createObject(testCase, {model: 2, wheelEnabled: true}) + verify(control) + + var delta = 120 + + mouseWheel(control, control.width / 2, control.height / 2, -delta, -delta) + compare(control.currentIndex, 1) + + // reached bounds -> no change + mouseWheel(control, control.width / 2, control.height / 2, -delta, -delta) + compare(control.currentIndex, 1) + + mouseWheel(control, control.width / 2, control.height / 2, delta, delta) + compare(control.currentIndex, 0) - idx1 = getChild(listview.contentItem, "delegate", -1) - compare(listview.contentItem.children[idx1].font.pixelSize, 25) - idx2 = getChild(listview.contentItem, "delegate", idx1) - compare(listview.contentItem.children[idx2].font.pixelSize, 25) + // reached bounds -> no change + mouseWheel(control, control.width / 2, control.height / 2, delta, delta) + compare(control.currentIndex, 0) control.destroy() } @@ -733,7 +892,7 @@ TestCase { // QTBUG-51645 function test_activation(data) { - var control = comboBox.createObject(window.contentItem, {currentIndex: 1, model: ["Apple", "Orange", "Banana"]}) + var control = comboBox.createObject(testCase, {currentIndex: 1, model: ["Apple", "Orange", "Banana"]}) verify(control) waitForRendering(control) @@ -781,4 +940,110 @@ TestCase { loader.destroy() } + + // QTBUG-52615 + function test_currentIndex() { + var control = comboBox.createObject(testCase, {currentIndex: -1, model: 3}) + verify(control) + + compare(control.currentIndex, -1) + + control.destroy() + } + + ListModel { + id: resetmodel + ListElement { text: "First" } + ListElement { text: "Second" } + ListElement { text: "Third" } + } + + // QTBUG-54573 + function test_modelReset() { + var control = comboBox.createObject(testCase, {model: resetmodel}) + verify(control) + control.popup.open() + + var listview = control.popup.contentItem + verify(listview) + + waitForRendering(listview) + compare(listview.contentItem.children.length, resetmodel.count + 1) // + highlight item + + resetmodel.clear() + resetmodel.append({text: "Fourth"}) + resetmodel.append({text: "Fifth"}) + + waitForRendering(listview) + compare(listview.contentItem.children.length, resetmodel.count + 1) // + highlight item + + control.destroy() + } + + // QTBUG-55118 + function test_currentText() { + var control = comboBox.createObject(testCase, {model: listmodel}) + verify(control) + + compare(control.currentIndex, 0) + compare(control.currentText, "First") + + listmodel.setProperty(0, "text", "1st") + compare(control.currentText, "1st") + + control.currentIndex = 1 + compare(control.currentText, "Second") + + listmodel.setProperty(0, "text", "First") + compare(control.currentText, "Second") + + control.destroy() + } + + // QTBUG-55030 + function test_highlightRange() { + var control = comboBox.createObject(testCase, {model: 100}) + verify(control) + + control.currentIndex = 50 + compare(control.currentIndex, 50) + compare(control.highlightedIndex, -1) + + var openedSpy = signalSpy.createObject(control, {target: control.popup, signalName: "opened"}) + verify(openedSpy.valid) + + control.popup.open() + compare(control.highlightedIndex, 50) + tryCompare(openedSpy, "count", 1) + + var listview = control.popup.contentItem + verify(listview) + + var first = listview.itemAt(0, listview.contentY) + verify(first) + compare(first.text, "50") + + var closedSpy = signalSpy.createObject(control, {target: control.popup, signalName: "closed"}) + verify(closedSpy.valid) + + control.popup.close() + tryCompare(closedSpy, "count", 1) + compare(control.highlightedIndex, -1) + + control.currentIndex = 99 + compare(control.currentIndex, 99) + compare(control.highlightedIndex, -1) + + control.popup.open() + compare(control.highlightedIndex, 99) + tryCompare(openedSpy, "count", 2) + + var last = listview.itemAt(0, listview.contentY + listview.height - 1) + verify(last) + compare(last.text, "99") + + openedSpy.target = null + closedSpy.target = null + control.destroy() + } } |