diff options
Diffstat (limited to 'tests/auto')
-rw-r--r-- | tests/auto/controls/data/TumblerListView.qml | 2 | ||||
-rw-r--r-- | tests/auto/controls/data/tst_combobox.qml | 368 | ||||
-rw-r--r-- | tests/auto/controls/data/tst_dial.qml | 60 | ||||
-rw-r--r-- | tests/auto/controls/data/tst_rangeslider.qml | 12 | ||||
-rw-r--r-- | tests/auto/controls/data/tst_slider.qml | 88 | ||||
-rw-r--r-- | tests/auto/controls/data/tst_swipedelegate.qml | 145 | ||||
-rw-r--r-- | tests/auto/controls/data/tst_tumbler.qml | 30 | ||||
-rw-r--r-- | tests/auto/drawer/tst_drawer.cpp | 57 | ||||
-rw-r--r-- | tests/auto/qquickstyle/tst_qquickstyle.cpp | 8 | ||||
-rw-r--r-- | tests/auto/revisions/tst_revisions.cpp | 10 | ||||
-rw-r--r-- | tests/auto/sanity/BLACKLIST | 8 | ||||
-rw-r--r-- | tests/auto/sanity/tst_sanity.cpp | 2 | ||||
-rw-r--r-- | tests/auto/shared/util.h | 2 |
13 files changed, 739 insertions, 53 deletions
diff --git a/tests/auto/controls/data/TumblerListView.qml b/tests/auto/controls/data/TumblerListView.qml index cccf8adf..1f55ddf7 100644 --- a/tests/auto/controls/data/TumblerListView.qml +++ b/tests/auto/controls/data/TumblerListView.qml @@ -48,6 +48,6 @@ ListView { snapMode: ListView.SnapToItem highlightRangeMode: ListView.StrictlyEnforceRange preferredHighlightBegin: height / 2 - (height / parent.visibleItemCount / 2) - preferredHighlightEnd: height / 2 + (height / parent.visibleItemCount / 2) + preferredHighlightEnd: height / 2 + (height / parent.visibleItemCount / 2) clip: true } diff --git a/tests/auto/controls/data/tst_combobox.qml b/tests/auto/controls/data/tst_combobox.qml index 2ba9be8f..68fe4c76 100644 --- a/tests/auto/controls/data/tst_combobox.qml +++ b/tests/auto/controls/data/tst_combobox.qml @@ -65,7 +65,7 @@ TestCase { id: emptyBox ComboBox { delegate: ItemDelegate { - width: popup.width + width: parent.width } } } @@ -713,6 +713,74 @@ TestCase { control.destroy() } + function test_down() { + var control = comboBox.createObject(testCase, {model: 3}) + verify(control) + + // some styles position the popup over the combo button. move it out + // of the way to avoid stealing mouse presses. we want to test the + // combinations of the button being pressed and the popup being visible. + control.popup.y = control.height + + var downSpy = signalSpy.createObject(control, {target: control, signalName: "downChanged"}) + verify(downSpy.valid) + + var pressedSpy = signalSpy.createObject(control, {target: control, signalName: "pressedChanged"}) + verify(pressedSpy.valid) + + mousePress(control) + compare(control.popup.visible, false) + compare(control.pressed, true) + compare(control.down, true) + compare(downSpy.count, 1) + compare(pressedSpy.count, 1) + + mouseRelease(control) + compare(control.popup.visible, true) + compare(control.pressed, false) + compare(control.down, true) + compare(downSpy.count, 3) + compare(pressedSpy.count, 2) + + control.down = false + compare(control.down, false) + compare(downSpy.count, 4) + + mousePress(control) + compare(control.popup.visible, true) + compare(control.pressed, true) + compare(control.down, false) // explicit false + compare(downSpy.count, 4) + compare(pressedSpy.count, 3) + + control.down = undefined + compare(control.down, true) + compare(downSpy.count, 5) + + mouseRelease(control) + tryCompare(control.popup, "visible", false) + compare(control.pressed, false) + compare(control.down, false) + compare(downSpy.count, 6) + compare(pressedSpy.count, 4) + + control.popup.open() + compare(control.popup.visible, true) + compare(control.pressed, false) + compare(control.down, true) + compare(downSpy.count, 7) + compare(pressedSpy.count, 4) + + control.popup.close() + tryCompare(control.popup, "visible", false) + compare(control.pressed, false) + compare(control.down, false) + compare(downSpy.count, 8) + compare(pressedSpy.count, 4) + + control.destroy() + } + function test_focus() { var control = comboBox.createObject(testCase, {model: 3}) verify(control) @@ -1047,4 +1115,302 @@ TestCase { closedSpy.target = null control.destroy() } + + RegExpValidator { + id: regExpValidator + regExp: /(red|blue|green)?/ + } + + function test_validator() { + var control = comboBox.createObject(testCase, {editable: true, validator: regExpValidator}) + + control.editText = "blu" + compare(control.acceptableInput, false) + control.editText = "blue" + compare(control.acceptableInput, true) + control.editText = "bluee" + compare(control.acceptableInput, false) + control.editText = "" + compare(control.acceptableInput, true) + control.editText = "" + control.forceActiveFocus() + keyPress(Qt.Key_A) + compare(control.editText, "") + keyPress(Qt.Key_A) + compare(control.editText, "") + keyPress(Qt.Key_R) + compare(control.editText, "r") + keyPress(Qt.Key_A) + compare(control.editText, "r") + compare(control.acceptableInput, false) + keyPress(Qt.Key_E) + compare(control.editText, "re") + compare(control.acceptableInput, false) + keyPress(Qt.Key_D) + compare(control.editText, "red") + compare(control.acceptableInput, true) + + control.destroy() + } + + Component { + id: appendFindBox + ComboBox { + editable: true + model: ListModel { + ListElement { text:"first" } + } + onAccepted: { + if (find(editText) === -1) + model.append({text: editText}) + } + } + } + + function test_append_find() { + var control = appendFindBox.createObject(testCase) + + compare(control.currentIndex, 0) + compare(control.currentText, "first") + control.forceActiveFocus() + compare(control.activeFocus, true) + + control.selectAll() + keyPress(Qt.Key_T) + keyPress(Qt.Key_H) + keyPress(Qt.Key_I) + keyPress(Qt.Key_R) + keyPress(Qt.Key_D) + compare(control.count, 1) + compare(control.currentText, "first") + compare(control.editText, "third") + + keyPress(Qt.Key_Enter) + compare(control.count, 2) + compare(control.currentIndex, 1) + compare(control.currentText, "third") + + control.destroy() + } + + function test_editable() { + var control = comboBox.createObject(testCase, {editable: true, model: ["Banana", "Coco", "Coconut", "Apple", "Cocomuffin"]}) + verify(control) + + control.forceActiveFocus() + verify(control.activeFocus) + + var acceptCount = 0 + + var acceptSpy = signalSpy.createObject(control, {target: control, signalName: "accepted"}) + verify(acceptSpy.valid) + + compare(control.editText, "Banana") + compare(control.currentText, "Banana") + compare(control.currentIndex, 0) + compare(acceptSpy.count, 0) + control.editText = "" + + keyPress(Qt.Key_C) + compare(control.editText, "coco") + compare(control.currentText, "Banana") + compare(control.currentIndex, 0) + + keyPress(Qt.Key_Right) + keyPress(Qt.Key_N) + compare(control.editText, "coconut") + compare(control.currentText, "Banana") + compare(control.currentIndex, 0) + + keyPress(Qt.Key_Enter) // Accept + compare(control.editText, "Coconut") + compare(control.currentText, "Coconut") + compare(control.currentIndex, 2) + compare(acceptSpy.count, ++acceptCount) + + keyPress(Qt.Key_Backspace) + keyPress(Qt.Key_Backspace) + keyPress(Qt.Key_Backspace) + keyPress(Qt.Key_M) + compare(control.editText, "Cocomuffin") + compare(control.currentText, "Coconut") + compare(control.currentIndex, 2) + + keyPress(Qt.Key_Enter) // Accept + compare(control.editText, "Cocomuffin") + compare(control.currentText, "Cocomuffin") + compare(control.currentIndex, 4) + compare(acceptSpy.count, ++acceptCount) + + keyPress(Qt.Key_Return) // Accept + compare(control.editText, "Cocomuffin") + compare(control.currentText, "Cocomuffin") + compare(control.currentIndex, 4) + compare(acceptSpy.count, ++acceptCount) + + control.editText = "" + compare(control.editText, "") + compare(control.currentText, "Cocomuffin") + compare(control.currentIndex, 4) + + keyPress(Qt.Key_A) + compare(control.editText, "apple") + compare(control.currentText, "Cocomuffin") + compare(control.currentIndex, 4) + + keyPress(Qt.Key_Return) // Accept + compare(control.editText, "Apple") + compare(control.currentText, "Apple") + compare(control.currentIndex, 3) + compare(acceptSpy.count, ++acceptCount) + + control.editText = "" + keyPress(Qt.Key_A) + keyPress(Qt.Key_B) + compare(control.editText, "ab") + compare(control.currentText, "Apple") + compare(control.currentIndex, 3) + + keyPress(Qt.Key_Return) // Accept + compare(control.editText, "ab") + compare(control.currentText, "") + compare(control.currentIndex, -1) + compare(acceptSpy.count, ++acceptCount) + + control.editText = "" + compare(control.editText, "") + compare(control.currentText, "") + compare(control.currentIndex, -1) + + keyPress(Qt.Key_C) + keyPress(Qt.Key_Return) // Accept + compare(control.editText, "Coco") + compare(control.currentText, "Coco") + compare(control.currentIndex, 1) + compare(acceptSpy.count, ++acceptCount) + + keyPress(Qt.Key_Down) + compare(control.editText, "Coconut") + compare(control.currentText, "Coconut") + compare(control.currentIndex, 2) + + keyPress(Qt.Key_Up) + compare(control.editText, "Coco") + compare(control.currentText, "Coco") + compare(control.currentIndex, 1) + + control.editText = "" + compare(control.editText, "") + compare(control.currentText, "Coco") + compare(control.currentIndex, 1) + + keyPress(Qt.Key_C) + keyPress(Qt.Key_O) + keyPress(Qt.Key_C) // autocompletes "coco" + keyPress(Qt.Key_Backspace) + keyPress(Qt.Key_Return) // Accept "coc" + compare(control.editText, "coc") + compare(control.currentText, "") + compare(control.currentIndex, -1) + compare(acceptSpy.count, ++acceptCount) + + control.editText = "" + compare(control.editText, "") + compare(control.currentText, "") + compare(control.currentIndex, -1) + + keyPress(Qt.Key_C) + keyPress(Qt.Key_O) + keyPress(Qt.Key_C) // autocompletes "coc" + keyPress(Qt.Key_Space) + keyPress(Qt.Key_Return) // Accept "coc " + compare(control.editText, "coc ") + compare(control.currentText, "") + compare(control.currentIndex, -1) + compare(acceptSpy.count, ++acceptCount) + + control.destroy() + } + + Component { + id: keysAttachedBox + ComboBox { + editable: true + property bool gotit: false + Keys.onPressed: { + if (!gotit && event.key === Qt.Key_B) { + gotit = true + event.accepted = true + } + } + } + } + + function test_keys_attached() { + var control = keysAttachedBox.createObject(testCase) + verify(control) + + control.forceActiveFocus() + verify(control.activeFocus) + + verify(!control.gotit) + compare(control.editText, "") + + keyPress(Qt.Key_A) + verify(control.activeFocus) + verify(!control.gotit) + compare(control.editText, "a") + + keyPress(Qt.Key_B) + verify(control.activeFocus) + expectFail("", "An editable ComboBox does not yet support the Keys attached property.") + verify(control.gotit) + compare(control.editText, "a") + + keyPress(Qt.Key_B) + verify(control.activeFocus) + verify(control.gotit) + compare(control.editText, "ab") + + control.destroy() + } + + function test_minusOneIndexResetsSelection_QTBUG_35794_data() { + return [ + { tag: "editable", editable: true }, + { tag: "non-editable", editable: false } + ] + } + + function test_minusOneIndexResetsSelection_QTBUG_35794(data) { + var control = comboBox.createObject(testCase, {editable: data.editable, model: ["A", "B", "C"]}) + verify(control) + + compare(control.currentIndex, 0) + compare(control.currentText, "A") + control.currentIndex = -1 + compare(control.currentIndex, -1) + compare(control.currentText, "") + control.currentIndex = 1 + compare(control.currentIndex, 1) + compare(control.currentText, "B") + + control.destroy() + } + + function test_minusOneToZeroSelection_QTBUG_38036() { + var control = comboBox.createObject(testCase, {model: ["A", "B", "C"]}) + verify(control) + + compare(control.currentIndex, 0) + compare(control.currentText, "A") + control.currentIndex = -1 + compare(control.currentIndex, -1) + compare(control.currentText, "") + control.currentIndex = 0 + compare(control.currentIndex, 0) + compare(control.currentText, "A") + + control.destroy() + } } diff --git a/tests/auto/controls/data/tst_dial.qml b/tests/auto/controls/data/tst_dial.qml index d0129755..c520aa4c 100644 --- a/tests/auto/controls/data/tst_dial.qml +++ b/tests/auto/controls/data/tst_dial.qml @@ -55,6 +55,11 @@ TestCase { Dial {} } + Component { + id: signalSpy + SignalSpy {} + } + property var dial: null function init() { @@ -172,9 +177,10 @@ TestCase { function test_dragging_data() { return [ - { tag: "default", from: 0, to: 1, leftValue: 0.20, topValue: 0.5, rightValue: 0.8, bottomValue: 1.0 }, - { tag: "scaled2", from: 0, to: 2, leftValue: 0.4, topValue: 1.0, rightValue: 1.6, bottomValue: 2.0 }, - { tag: "scaled1", from: -1, to: 0, leftValue: -0.8, topValue: -0.5, rightValue: -0.2, bottomValue: 0.0 } + { tag: "default", from: 0, to: 1, leftValue: 0.20, topValue: 0.5, rightValue: 0.8, bottomValue: 1.0, live: false }, + { tag: "scaled2", from: 0, to: 2, leftValue: 0.4, topValue: 1.0, rightValue: 1.6, bottomValue: 2.0, live: false }, + { tag: "scaled1", from: -1, to: 0, leftValue: -0.8, topValue: -0.5, rightValue: -0.2, bottomValue: 0.0, live: false }, + { tag: "live", from: 0, to: 1, leftValue: 0.20, topValue: 0.5, rightValue: 0.8, bottomValue: 1.0, live: true } ] } @@ -183,33 +189,47 @@ TestCase { verify(dial.wrap); dial.from = data.from; dial.to = data.to; + dial.live = data.live; valueSpy.target = dial; verify(valueSpy.valid); + var moveSpy = signalSpy.createObject(testCase, {target: dial, signalName: "moved"}); + verify(moveSpy.valid); + + var minimumExpectedValueCount = data.live ? 2 : 1; + // drag to the left mouseDrag(dial, dial.width / 2, dial.height / 2, -dial.width / 2, 0, Qt.LeftButton); fuzzyCompare(dial.value, data.leftValue, 0.1); - verify(valueSpy.count > 0); + verify(valueSpy.count >= minimumExpectedValueCount); valueSpy.clear(); + verify(moveSpy.count > 0); + moveSpy.clear(); // drag to the top mouseDrag(dial, dial.width / 2, dial.height / 2, 0, -dial.height / 2, Qt.LeftButton); fuzzyCompare(dial.value, data.topValue, 0.1); - verify(valueSpy.count > 0); + verify(valueSpy.count >= minimumExpectedValueCount); valueSpy.clear(); + verify(moveSpy.count > 0); + moveSpy.clear(); // drag to the right mouseDrag(dial, dial.width / 2, dial.height / 2, dial.width / 2, 0, Qt.LeftButton); fuzzyCompare(dial.value, data.rightValue, 0.1); - verify(valueSpy.count > 0); + verify(valueSpy.count >= minimumExpectedValueCount); valueSpy.clear(); + verify(moveSpy.count > 0); + moveSpy.clear(); // drag to the bottom (* 0.6 to ensure we don't go over to the minimum position) mouseDrag(dial, dial.width / 2, dial.height / 2, 10, dial.height / 2, Qt.LeftButton); fuzzyCompare(dial.value, data.bottomValue, 0.1); - verify(valueSpy.count > 0); + verify(valueSpy.count >= minimumExpectedValueCount); valueSpy.clear(); + verify(moveSpy.count > 0); + moveSpy.clear(); } function test_nonWrapping() { @@ -267,10 +287,15 @@ TestCase { var focusScope = focusTest.createObject(testCase); verify(focusScope); + var moveCount = 0; + // Tests that we've accepted events that we're interested in. parentEventSpy.target = focusScope; parentEventSpy.signalName = "receivedKeyPress"; + var moveSpy = signalSpy.createObject(testCase, {target: dial, signalName: "moved"}); + verify(moveSpy.valid); + dial.parent = focusScope; compare(dial.activeFocusOnTab, true); compare(dial.value, 0); @@ -281,44 +306,55 @@ TestCase { keyClick(Qt.Key_Left); compare(parentEventSpy.count, 0); + compare(moveSpy.count, moveCount); compare(dial.value, 0); - + var oldValue = 0.0; var keyPairs = [[Qt.Key_Left, Qt.Key_Right], [Qt.Key_Down, Qt.Key_Up]]; for (var keyPairIndex = 0; keyPairIndex < 2; ++keyPairIndex) { for (var i = 1; i <= 10; ++i) { + oldValue = dial.value; keyClick(keyPairs[keyPairIndex][1]); compare(parentEventSpy.count, 0); + if (oldValue !== dial.value) + compare(moveSpy.count, ++moveCount); compare(dial.value, dial.stepSize * i); } compare(dial.value, dial.to); for (i = 10; i > 0; --i) { + oldValue = dial.value; keyClick(keyPairs[keyPairIndex][0]); compare(parentEventSpy.count, 0); + if (oldValue !== dial.value) + compare(moveSpy.count, ++moveCount); compare(dial.value, dial.stepSize * (i - 1)); } } + dial.value = 0.5; + + keyClick(Qt.Key_Home); + compare(parentEventSpy.count, 0); + compare(moveSpy.count, ++moveCount); compare(dial.value, dial.from); keyClick(Qt.Key_Home); compare(parentEventSpy.count, 0); + compare(moveSpy.count, moveCount); compare(dial.value, dial.from); keyClick(Qt.Key_End); compare(parentEventSpy.count, 0); + compare(moveSpy.count, ++moveCount); compare(dial.value, dial.to); keyClick(Qt.Key_End); compare(parentEventSpy.count, 0); + compare(moveSpy.count, moveCount); compare(dial.value, dial.to); - keyClick(Qt.Key_Home); - compare(parentEventSpy.count, 0); - compare(dial.value, dial.from); - focusScope.destroy(); } diff --git a/tests/auto/controls/data/tst_rangeslider.qml b/tests/auto/controls/data/tst_rangeslider.qml index eb654bbc..42155dc0 100644 --- a/tests/auto/controls/data/tst_rangeslider.qml +++ b/tests/auto/controls/data/tst_rangeslider.qml @@ -40,7 +40,7 @@ import QtQuick 2.2 import QtTest 1.0 -import QtQuick.Controls 2.1 +import QtQuick.Controls 2.2 TestCase { id: testCase @@ -274,13 +274,15 @@ TestCase { function test_mouse_data() { return [ - { tag: "horizontal", orientation: Qt.Horizontal }, - { tag: "vertical", orientation: Qt.Vertical } + { tag: "horizontal", orientation: Qt.Horizontal, live: false }, + { tag: "vertical", orientation: Qt.Vertical, live: false }, + { tag: "horizontal:live", orientation: Qt.Horizontal, live: true }, + { tag: "vertical:live", orientation: Qt.Vertical, live: true } ] } function test_mouse(data) { - var control = sliderComponent.createObject(testCase, { orientation: data.orientation }) + var control = sliderComponent.createObject(testCase, { orientation: data.orientation, live: data.live }) verify(control) var firstPressedSpy = signalSpy.createObject(control, {target: control.first, signalName: "pressedChanged"}) @@ -366,7 +368,7 @@ TestCase { compare(firstPressedSpy.count, 5) compare(secondPressedSpy.count, 2) compare(control.first.pressed, true) - compare(control.first.value, 0.0) + compare(control.first.value, data.live ? 0.5 : 0.0) compare(control.first.position, 0.5) compare(control.first.visualPosition, 0.5) compare(control.second.pressed, false) diff --git a/tests/auto/controls/data/tst_slider.qml b/tests/auto/controls/data/tst_slider.qml index 029aff14..a5d6d36d 100644 --- a/tests/auto/controls/data/tst_slider.qml +++ b/tests/auto/controls/data/tst_slider.qml @@ -40,7 +40,7 @@ import QtQuick 2.2 import QtTest 1.0 -import QtQuick.Controls 2.1 +import QtQuick.Controls 2.2 TestCase { id: testCase @@ -213,64 +213,80 @@ TestCase { function test_mouse_data() { return [ - { tag: "horizontal", orientation: Qt.Horizontal }, - { tag: "vertical", orientation: Qt.Vertical } + { tag: "horizontal", orientation: Qt.Horizontal, live: false }, + { tag: "vertical", orientation: Qt.Vertical, live: false }, + { tag: "horizontal:live", orientation: Qt.Horizontal, live: true }, + { tag: "vertical:live", orientation: Qt.Vertical, live: true } ] } function test_mouse(data) { - var control = slider.createObject(testCase, {orientation: data.orientation}) + var control = slider.createObject(testCase, {orientation: data.orientation, live: data.live}) verify(control) + var pressedCount = 0 + var movedCount = 0 + var pressedSpy = signalSpy.createObject(control, {target: control, signalName: "pressedChanged"}) verify(pressedSpy.valid) + var movedSpy = signalSpy.createObject(control, {target: control, signalName: "moved"}) + verify(movedSpy.valid) + mousePress(control, 0, 0, Qt.LeftButton) - compare(pressedSpy.count, 1) + compare(pressedSpy.count, ++pressedCount) + compare(movedSpy.count, movedCount) compare(control.pressed, true) compare(control.value, 0.0) compare(control.position, 0.0) // mininum on the left in horizontal vs. at the bottom in vertical mouseMove(control, -control.width, 2 * control.height, 0, Qt.LeftButton) - compare(pressedSpy.count, 1) + compare(pressedSpy.count, pressedCount) + compare(movedSpy.count, movedCount) compare(control.pressed, true) compare(control.value, 0.0) compare(control.position, 0.0) mouseMove(control, control.width * 0.5, control.height * 0.5, 0, Qt.LeftButton) - compare(pressedSpy.count, 1) + compare(pressedSpy.count, pressedCount) + compare(movedSpy.count, ++movedCount) compare(control.pressed, true) - compare(control.value, 0.0) - verify(control.position, 0.5) + compare(control.value, data.live ? 0.5 : 0.0) + compare(control.position, 0.5) mouseRelease(control, control.width * 0.5, control.height * 0.5, Qt.LeftButton) - compare(pressedSpy.count, 2) + compare(pressedSpy.count, ++pressedCount) + compare(movedSpy.count, movedCount) compare(control.pressed, false) compare(control.value, 0.5) compare(control.position, 0.5) mousePress(control, control.width, control.height, Qt.LeftButton) - compare(pressedSpy.count, 3) + compare(pressedSpy.count, ++pressedCount) + compare(movedSpy.count, movedCount) compare(control.pressed, true) compare(control.value, 0.5) compare(control.position, 0.5) // maximum on the right in horizontal vs. at the top in vertical mouseMove(control, control.width * 2, -control.height, 0, Qt.LeftButton) - compare(pressedSpy.count, 3) + compare(pressedSpy.count, pressedCount) + compare(movedSpy.count, ++movedCount) compare(control.pressed, true) - compare(control.value, 0.5) + compare(control.value, data.live ? 1.0 : 0.5) compare(control.position, 1.0) mouseMove(control, control.width * 0.75, control.height * 0.25, 0, Qt.LeftButton) - compare(pressedSpy.count, 3) + compare(pressedSpy.count, pressedCount) + compare(movedSpy.count, ++movedCount) compare(control.pressed, true) - compare(control.value, 0.5) + compare(control.value, data.live ? control.position : 0.5) verify(control.position >= 0.75) mouseRelease(control, control.width * 0.25, control.height * 0.75, Qt.LeftButton) - compare(pressedSpy.count, 4) + compare(pressedSpy.count, ++pressedCount) + compare(movedSpy.count, ++movedCount) compare(control.pressed, false) compare(control.value, control.position) verify(control.value <= 0.25 && control.value >= 0.0) @@ -278,7 +294,8 @@ TestCase { // QTBUG-53846 mouseClick(control, control.width * 0.5, control.height * 0.5, Qt.LeftButton) - compare(pressedSpy.count, 6) + compare(movedSpy.count, ++movedCount) + compare(pressedSpy.count, pressedCount += 2) compare(control.value, 0.5) compare(control.position, 0.5) @@ -297,19 +314,27 @@ TestCase { verify(control) var pressedCount = 0 + var movedCount = 0 var pressedSpy = signalSpy.createObject(control, {target: control, signalName: "pressedChanged"}) verify(pressedSpy.valid) + var movedSpy = signalSpy.createObject(control, {target: control, signalName: "moved"}) + verify(movedSpy.valid) + control.forceActiveFocus() verify(control.activeFocus) + var oldValue = 0.0 control.value = 0.5 for (var d1 = 1; d1 <= 10; ++d1) { + oldValue = control.value keyPress(data.decrease) compare(control.pressed, true) compare(pressedSpy.count, ++pressedCount) + if (oldValue !== control.value) + compare(movedSpy.count, ++movedCount) compare(control.value, Math.max(0.0, 0.5 - d1 * 0.1)) compare(control.value, control.position) @@ -317,12 +342,16 @@ TestCase { keyRelease(data.decrease) compare(control.pressed, false) compare(pressedSpy.count, ++pressedCount) + compare(movedSpy.count, movedCount) } for (var i1 = 1; i1 <= 20; ++i1) { + oldValue = control.value keyPress(data.increase) compare(control.pressed, true) compare(pressedSpy.count, ++pressedCount) + if (oldValue !== control.value) + compare(movedSpy.count, ++movedCount) compare(control.value, Math.min(1.0, 0.0 + i1 * 0.1)) compare(control.value, control.position) @@ -330,14 +359,18 @@ TestCase { keyRelease(data.increase) compare(control.pressed, false) compare(pressedSpy.count, ++pressedCount) + compare(movedSpy.count, movedCount) } control.stepSize = 0.25 for (var d2 = 1; d2 <= 10; ++d2) { + oldValue = control.value keyPress(data.decrease) compare(control.pressed, true) compare(pressedSpy.count, ++pressedCount) + if (oldValue !== control.value) + compare(movedSpy.count, ++movedCount) compare(control.value, Math.max(0.0, 1.0 - d2 * 0.25)) compare(control.value, control.position) @@ -345,12 +378,16 @@ TestCase { keyRelease(data.decrease) compare(control.pressed, false) compare(pressedSpy.count, ++pressedCount) + compare(movedSpy.count, movedCount) } for (var i2 = 1; i2 <= 10; ++i2) { + oldValue = control.value keyPress(data.increase) compare(control.pressed, true) compare(pressedSpy.count, ++pressedCount) + if (oldValue !== control.value) + compare(movedSpy.count, ++movedCount) compare(control.value, Math.min(1.0, 0.0 + i2 * 0.25)) compare(control.value, control.position) @@ -358,6 +395,7 @@ TestCase { keyRelease(data.increase) compare(control.pressed, false) compare(pressedSpy.count, ++pressedCount) + compare(movedSpy.count, movedCount) } control.destroy() @@ -485,21 +523,34 @@ TestCase { var control = slider.createObject(testCase, {wheelEnabled: true, orientation: data.orientation}) verify(control) + var movedCount = 0 + var movedSpy = signalSpy.createObject(control, {target: control, signalName: "moved"}) + verify(movedSpy.valid) + compare(control.value, 0.0) mouseWheel(control, control.width / 2, control.height / 2, data.dx, data.dy) + compare(movedSpy.count, ++movedCount) compare(control.value, 0.1) compare(control.position, 0.1) control.stepSize = 0.2 mouseWheel(control, control.width / 2, control.height / 2, data.dx, data.dy) + compare(movedSpy.count, ++movedCount) compare(control.value, 0.3) compare(control.position, 0.3) control.stepSize = 10.0 mouseWheel(control, control.width / 2, control.height / 2, -data.dx, -data.dy) + compare(movedSpy.count, ++movedCount) + compare(control.value, 0.0) + compare(control.position, 0.0) + + // no change + mouseWheel(control, control.width / 2, control.height / 2, -data.dx, -data.dy) + compare(movedSpy.count, movedCount) compare(control.value, 0.0) compare(control.position, 0.0) @@ -507,14 +558,17 @@ TestCase { control.stepSize = 5.0 mouseWheel(control, control.width / 2, control.height / 2, data.dx, data.dy) + compare(movedSpy.count, ++movedCount) compare(control.value, 5.0) compare(control.position, 0.5) mouseWheel(control, control.width / 2, control.height / 2, 0.5 * data.dx, 0.5 * data.dy) + compare(movedSpy.count, ++movedCount) compare(control.value, 7.5) compare(control.position, 0.75) mouseWheel(control, control.width / 2, control.height / 2, -data.dx, -data.dy) + compare(movedSpy.count, ++movedCount) compare(control.value, 2.5) compare(control.position, 0.25) diff --git a/tests/auto/controls/data/tst_swipedelegate.qml b/tests/auto/controls/data/tst_swipedelegate.qml index 7a2ad44d..a6e11246 100644 --- a/tests/auto/controls/data/tst_swipedelegate.qml +++ b/tests/auto/controls/data/tst_swipedelegate.qml @@ -1369,6 +1369,151 @@ TestCase { } Component { + id: swipeDelegateDisabledComponent + + SwipeDelegate { + id: swipeDelegate + text: "SwipeDelegate" + width: parent.width + height: checked ? implicitHeight * 2 : implicitHeight + checkable: true + + swipe.enabled: false + swipe.right: Label { + text: swipeDelegate.checked ? qsTr("Expanded") : qsTr("Collapsed") + width: parent.width + height: parent.height + padding: 12 + color: "white" + verticalAlignment: Label.AlignVCenter + horizontalAlignment: Label.AlignRight + } + } + } + + function test_swipeEnabled() { + var control = swipeDelegateDisabledComponent.createObject(testCase); + + mousePress(control, control.width / 2, control.height / 2); + verify(control.pressed); + compare(control.swipe.position, 0.0); + verify(!control.swipe.complete); + verify(!control.swipe.leftItem); + verify(!control.swipe.rightItem); + + // It shouldn't be possible to swipe. + var overDragDistance = Math.round(dragDistance * 1.1); + mouseMove(control, control.width / 2 - overDragDistance, control.height / 2); + verify(control.pressed); + compare(control.swipe.position, 0.0); + verify(!control.swipe.complete); + verify(!control.swipe.leftItem); + verify(!control.swipe.rightItem); + + // Now move outside the right edge of the control and release. + mouseMove(control, control.width * 1.1, control.height / 2); + verify(control.pressed); + compare(control.swipe.position, 0.0); + verify(!control.swipe.complete); + verify(!control.swipe.leftItem); + verify(!control.swipe.rightItem); + + mouseRelease(control, control.width / 2, control.height / 2); + verify(!control.pressed); + compare(control.swipe.position, 0.0); + verify(!control.swipe.complete); + verify(!control.swipe.leftItem); + verify(!control.swipe.rightItem); + + // Now enabled swiping so that we can swipe to the left. + control.swipe.enabled = true; + swipe(control, 0, -1); + verify(control.swipe.complete); + + // Now that the swipe is complete, disable swiping and then try to swipe again. + // It should stay at its position of -1. + control.swipe.enabled = false; + + mousePress(control, control.width / 2, control.height / 2); + verify(control.pressed); + compare(control.swipe.position, -1.0); + + mouseMove(control, control.width / 2 + overDragDistance, control.height / 2); + verify(control.pressed); + compare(control.swipe.position, -1.0); + verify(control.swipe.complete); + + mouseRelease(control, control.width / 2 + overDragDistance, control.height / 2); + verify(!control.pressed); + compare(control.swipe.position, -1.0); + verify(control.swipe.complete); + + control.destroy(); + } + + function test_side() { + compare(SwipeDelegate.Left, 1.0); + compare(SwipeDelegate.Right, -1.0); + } + + function test_open_side_data() { + return [ + { tag: "left", side: SwipeDelegate.Left, position: 1, complete: true, left: greenLeftComponent, right: null, behind: null }, + { tag: "right", side: SwipeDelegate.Right, position: -1, complete: true, left: null, right: redRightComponent, behind: null }, + { tag: "behind,left", side: SwipeDelegate.Left, position: 1, complete: true, left: null, right: null, behind: greenLeftComponent }, + { tag: "behind,right", side: SwipeDelegate.Right, position: -1, complete: true, left: null, right: null, behind: redRightComponent }, + { tag: "left,behind", side: SwipeDelegate.Left, position: 1, complete: true, left: null, right: null, behind: greenLeftComponent }, + { tag: "right,behind", side: SwipeDelegate.Right, position: -1, complete: true, left: null, right: null, behind: redRightComponent }, + { tag: "left,null", side: SwipeDelegate.Left, position: 0, complete: false, left: null, right: null, behind: null }, + { tag: "right,null", side: SwipeDelegate.Right, position: 0, complete: false, left: null, right: null, behind: null }, + { tag: "invalid", side: 0, position: 0, complete: false, left: greenLeftComponent, right: null, behind: null } + ] + } + + function test_open_side(data) { + var control = emptySwipeDelegateComponent.createObject(testCase, {"swipe.left": data.left, "swipe.right": data.right, "swipe.behind": data.behind}); + verify(control); + + control.swipe.open(data.side); + compare(control.swipe.position, data.position); + compare(control.swipe.complete, data.complete); + + control.destroy(); + } + + Component { + id: openSwipeDelegateComponent + + SwipeDelegate { + text: "SwipeDelegate" + width: 150 + + onClicked: swipe.open(SwipeDelegate.Right) + + swipe.right: Item { + width: parent.width + height: parent.height + } + } + } + + function test_open() { + var control = openSwipeDelegateComponent.createObject(testCase); + verify(control); + + mouseClick(control); + compare(control.swipe.position, SwipeDelegate.Right); + tryCompare(control.background, "x", -control.background.width); + + // Swiping after opening should work as normal. + swipe(control, SwipeDelegate.Right, 0.0); + compare(control.swipe.position, 0.0); + tryCompare(control.background, "x", 0); + + control.destroy(); + } + + Component { id: animationSwipeDelegateComponent SwipeDelegate { diff --git a/tests/auto/controls/data/tst_tumbler.qml b/tests/auto/controls/data/tst_tumbler.qml index 01d5cdee..cde319ea 100644 --- a/tests/auto/controls/data/tst_tumbler.qml +++ b/tests/auto/controls/data/tst_tumbler.qml @@ -40,7 +40,7 @@ import QtQuick 2.2 import QtTest 1.0 -import QtQuick.Controls 2.1 +import QtQuick.Controls 2.2 TestCase { id: testCase @@ -623,7 +623,7 @@ TestCase { snapMode: ListView.SnapToItem highlightRangeMode: ListView.StrictlyEnforceRange preferredHighlightBegin: height / 2 - (height / listViewTumbler.visibleItemCount / 2) - preferredHighlightEnd: height / 2 + (height / listViewTumbler.visibleItemCount / 2) + preferredHighlightEnd: height / 2 + (height / listViewTumbler.visibleItemCount / 2) clip: true } } @@ -1039,4 +1039,30 @@ TestCase { ++tumbler.currentIndex; tryCompare(tumblerView, "offset", 4, tumblerView.highlightMoveDuration * 2); } + + function test_moving_data() { + return [ + { tag: "wrap:true", wrap: true }, + { tag: "wrap:false", wrap: false } + ] + } + + function test_moving(data) { + createTumbler({wrap: data.wrap, model: 5}) + compare(tumbler.wrap, data.wrap) + compare(tumbler.moving, false) + + waitForRendering(tumbler) + + mousePress(tumbler, tumbler.width / 2, tumbler.height / 2, Qt.LeftButton) + compare(tumbler.moving, false) + + for (var y = tumbler.height / 2; y >= tumbler.height / 4; y -= 10) + mouseMove(tumbler, tumbler.width / 2, y, 1) + compare(tumbler.moving, true) + + mouseRelease(tumbler, tumbler.width / 2, tumbler.height / 4, Qt.LeftButton) + compare(tumbler.moving, true) + tryCompare(tumbler, "moving", false) + } } diff --git a/tests/auto/drawer/tst_drawer.cpp b/tests/auto/drawer/tst_drawer.cpp index 4743a8cd..7098ddc4 100644 --- a/tests/auto/drawer/tst_drawer.cpp +++ b/tests/auto/drawer/tst_drawer.cpp @@ -84,6 +84,9 @@ private slots: void touch(); void grabber(); + + void interactive_data(); + void interactive(); }; void tst_Drawer::visible_data() @@ -799,6 +802,60 @@ void tst_Drawer::grabber() QTRY_COMPARE(popupClosedSpy.count(), 1); } +void tst_Drawer::interactive_data() +{ + QTest::addColumn<QString>("source"); + QTest::newRow("Window") << "window.qml"; + QTest::newRow("ApplicationWindow") << "applicationwindow.qml"; +} + +void tst_Drawer::interactive() +{ + QFETCH(QString, source); + QQuickApplicationHelper helper(this, source); + + QQuickWindow *window = helper.window; + window->show(); + QVERIFY(QTest::qWaitForWindowActive(window)); + + QQuickDrawer *drawer = window->property("drawer").value<QQuickDrawer*>(); + QVERIFY(drawer); + + drawer->setInteractive(false); + + QSignalSpy openedSpy(drawer, SIGNAL(opened())); + QSignalSpy aboutToHideSpy(drawer, SIGNAL(aboutToHide())); + QVERIFY(openedSpy.isValid()); + QVERIFY(aboutToHideSpy.isValid()); + + drawer->open(); + QVERIFY(openedSpy.wait()); + + // click outside + QTest::mouseClick(window, Qt::LeftButton, Qt::NoModifier, QPoint(300, 100)); + QCOMPARE(aboutToHideSpy.count(), 0); + + // drag inside + QTest::mousePress(window, Qt::LeftButton, Qt::NoModifier, QPoint(drawer->width(), 0)); + QTest::mouseMove(window, QPoint(0, 0)); + QCOMPARE(drawer->position(), 1.0); + QTest::mouseRelease(window, Qt::LeftButton, Qt::NoModifier, QPoint(0, 0)); + QCOMPARE(drawer->position(), 1.0); + QCOMPARE(aboutToHideSpy.count(), 0); + + // drag outside + QTest::mousePress(window, Qt::LeftButton, Qt::NoModifier, QPoint(window->width() - 1, 0)); + QTest::mouseMove(window, QPoint(0, 0)); + QCOMPARE(drawer->position(), 1.0); + QTest::mouseRelease(window, Qt::LeftButton, Qt::NoModifier, QPoint(0, 0)); + QCOMPARE(drawer->position(), 1.0); + QCOMPARE(aboutToHideSpy.count(), 0); + + // close on escape + QTest::keyClick(window, Qt::Key_Escape); + QCOMPARE(aboutToHideSpy.count(), 0); +} + QTEST_MAIN(tst_Drawer) #include "tst_drawer.moc" diff --git a/tests/auto/qquickstyle/tst_qquickstyle.cpp b/tests/auto/qquickstyle/tst_qquickstyle.cpp index 15edc67b..cc9cc75d 100644 --- a/tests/auto/qquickstyle/tst_qquickstyle.cpp +++ b/tests/auto/qquickstyle/tst_qquickstyle.cpp @@ -50,6 +50,7 @@ private slots: void lookup(); void commandLineArgument(); void environmentVariables(); + void availableStyles(); }; void tst_QQuickStyle::init() @@ -94,6 +95,13 @@ void tst_QQuickStyle::environmentVariables() QCOMPARE(QQuickStylePrivate::fallbackStyle(), QString("EnvVarFallbackStyle")); } +void tst_QQuickStyle::availableStyles() +{ + QStringList styles = QQuickStyle::availableStyles(); + QVERIFY(!styles.isEmpty()); + QCOMPARE(styles.first(), QString("Default")); +} + QTEST_MAIN(tst_QQuickStyle) #include "tst_qquickstyle.moc" diff --git a/tests/auto/revisions/tst_revisions.cpp b/tests/auto/revisions/tst_revisions.cpp index 33649d62..ef1eb1f9 100644 --- a/tests/auto/revisions/tst_revisions.cpp +++ b/tests/auto/revisions/tst_revisions.cpp @@ -52,12 +52,9 @@ void tst_revisions::revisions_data() { QTest::addColumn<int>("revision"); - // In theory, this could be done in a loop from 5.7 to QT_VERSION, but - // the test would immediately fail when the Qt version was bumped up. - // Therefore it is better to just add these lines by hand when adding - // new revisions. - QTest::newRow("2.0") << 0; // Qt 5.7 - QTest::newRow("2.1") << 1; // Qt 5.8 + // Qt 5.7: 2.0, Qt 5.8: 2.1, Qt 5.9: 2.2... + for (int i = 0; i <= QT_VERSION_MINOR - 7; ++i) + QTest::newRow(qPrintable(QString("2.%1").arg(i))) << i; } void tst_revisions::revisions() @@ -67,6 +64,7 @@ void tst_revisions::revisions() QQmlEngine engine; QQmlComponent component(&engine); component.setData(QString("import QtQuick 2.0; \ + import QtQuick.Templates 2.%1 as T; \ import QtQuick.Controls 2.%1; \ import QtQuick.Controls.impl 2.%1; \ import QtQuick.Controls.Material 2.%1; \ diff --git a/tests/auto/sanity/BLACKLIST b/tests/auto/sanity/BLACKLIST index 768f3985..965790e7 100644 --- a/tests/auto/sanity/BLACKLIST +++ b/tests/auto/sanity/BLACKLIST @@ -1,10 +1,4 @@ -[signalHandlers:material/SpinBox.qml] -* -[signalHandlers:material/TextArea.qml] -* -[signalHandlers:material/TextField.qml] -* -[attachedObjects:controls/ComboBox.qml] +[signalHandlers:material/CursorDelegate.qml] * [attachedObjects:material/ComboBox.qml] * diff --git a/tests/auto/sanity/tst_sanity.cpp b/tests/auto/sanity/tst_sanity.cpp index 23b56384..823cbc02 100644 --- a/tests/auto/sanity/tst_sanity.cpp +++ b/tests/auto/sanity/tst_sanity.cpp @@ -314,7 +314,7 @@ void tst_Sanity::attachedObjects_data() QTest::addColumn<QUrl>("url"); addTestRows(&engine, "calendar", "Qt/labs/calendar"); addTestRows(&engine, "controls", "QtQuick/Controls.2", QStringList() << "CheckIndicator" << "RadioIndicator" << "SwitchIndicator"); - addTestRows(&engine, "controls/material", "QtQuick/Controls.2/Material", QStringList() << "Ripple" << "SliderHandle" << "CheckIndicator" << "RadioIndicator" << "SwitchIndicator" << "BoxShadow" << "ElevationEffect"); + addTestRows(&engine, "controls/material", "QtQuick/Controls.2/Material", QStringList() << "Ripple" << "SliderHandle" << "CheckIndicator" << "RadioIndicator" << "SwitchIndicator" << "BoxShadow" << "ElevationEffect" << "CursorDelegate"); addTestRows(&engine, "controls/universal", "QtQuick/Controls.2/Universal", QStringList() << "CheckIndicator" << "RadioIndicator" << "SwitchIndicator"); } diff --git a/tests/auto/shared/util.h b/tests/auto/shared/util.h index 80d301bc..fa934b34 100644 --- a/tests/auto/shared/util.h +++ b/tests/auto/shared/util.h @@ -65,7 +65,7 @@ public: inline QString dataDirectory() const { return m_dataDirectory; } inline QUrl dataDirectoryUrl() const { return m_dataDirectoryUrl; } - inline QString directory() const { return m_directory; } + inline QString directory() const { return m_directory; } static inline QQmlDataTest *instance() { return m_instance; } |