diff options
Diffstat (limited to 'tests/auto/quickcontrols/controls/data')
65 files changed, 4811 insertions, 2007 deletions
diff --git a/tests/auto/quickcontrols/controls/data/SignalSequenceSpy.qml b/tests/auto/quickcontrols/controls/data/SignalSequenceSpy.qml index 5e536248a8..879e7e546f 100644 --- a/tests/auto/quickcontrols/controls/data/SignalSequenceSpy.qml +++ b/tests/auto/quickcontrols/controls/data/SignalSequenceSpy.qml @@ -1,5 +1,5 @@ // Copyright (C) 2017 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only import QtQuick diff --git a/tests/auto/quickcontrols/controls/data/TestItem.qml b/tests/auto/quickcontrols/controls/data/TestItem.qml index c36ddc2f11..7f01b2231a 100644 --- a/tests/auto/quickcontrols/controls/data/TestItem.qml +++ b/tests/auto/quickcontrols/controls/data/TestItem.qml @@ -1,5 +1,5 @@ // Copyright (C) 2017 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only import QtQuick diff --git a/tests/auto/quickcontrols/controls/data/TumblerDatePicker.qml b/tests/auto/quickcontrols/controls/data/TumblerDatePicker.qml index c1b12e8fbc..bb24557fe2 100644 --- a/tests/auto/quickcontrols/controls/data/TumblerDatePicker.qml +++ b/tests/auto/quickcontrols/controls/data/TumblerDatePicker.qml @@ -1,5 +1,5 @@ // Copyright (C) 2017 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only import QtQuick import QtQuick.Controls diff --git a/tests/auto/quickcontrols/controls/data/TumblerListView.qml b/tests/auto/quickcontrols/controls/data/TumblerListView.qml index a794f255db..ccc44cfe15 100644 --- a/tests/auto/quickcontrols/controls/data/TumblerListView.qml +++ b/tests/auto/quickcontrols/controls/data/TumblerListView.qml @@ -1,5 +1,5 @@ // Copyright (C) 2017 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only import QtQuick import QtQuick.Controls diff --git a/tests/auto/quickcontrols/controls/data/TumblerPathView.qml b/tests/auto/quickcontrols/controls/data/TumblerPathView.qml index 26de69dab2..971369a2dd 100644 --- a/tests/auto/quickcontrols/controls/data/TumblerPathView.qml +++ b/tests/auto/quickcontrols/controls/data/TumblerPathView.qml @@ -1,5 +1,5 @@ // Copyright (C) 2017 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only import QtQuick import QtQuick.Controls diff --git a/tests/auto/quickcontrols/controls/data/combobox/shader.frag b/tests/auto/quickcontrols/controls/data/combobox/shader.frag new file mode 100644 index 0000000000..fbbef218e6 --- /dev/null +++ b/tests/auto/quickcontrols/controls/data/combobox/shader.frag @@ -0,0 +1,19 @@ +// Copyright (C) 2024 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#version 440 + +layout(location = 0) in vec2 qt_TexCoord0; +layout(location = 0) out vec4 fragColor; +layout(binding = 1) uniform sampler2D source; // this item + +layout(std140, binding = 0) uniform buf { + float qt_Opacity; // inherited opacity of this item +}; + + +void main() { + vec4 p = texture(source, qt_TexCoord0); + lowp float g = dot(p.xyz, vec3(0.344, 0.5, 0.156)); + fragColor = vec4(g, g, g, p.a) * qt_Opacity; +} diff --git a/tests/auto/quickcontrols/controls/data/combobox/shader.frag.qsb b/tests/auto/quickcontrols/controls/data/combobox/shader.frag.qsb Binary files differnew file mode 100644 index 0000000000..b86ce9a76e --- /dev/null +++ b/tests/auto/quickcontrols/controls/data/combobox/shader.frag.qsb diff --git a/tests/auto/quickcontrols/controls/data/splitview/fillItemInMiddle.qml b/tests/auto/quickcontrols/controls/data/splitview/fillItemInMiddle.qml index 1849e66e1c..63e0028220 100644 --- a/tests/auto/quickcontrols/controls/data/splitview/fillItemInMiddle.qml +++ b/tests/auto/quickcontrols/controls/data/splitview/fillItemInMiddle.qml @@ -1,5 +1,5 @@ // Copyright (C) 2018 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only import QtQuick import QtQuick.Controls diff --git a/tests/auto/quickcontrols/controls/data/splitview/fillItemOnLeft.qml b/tests/auto/quickcontrols/controls/data/splitview/fillItemOnLeft.qml index 8307a05951..815e764215 100644 --- a/tests/auto/quickcontrols/controls/data/splitview/fillItemOnLeft.qml +++ b/tests/auto/quickcontrols/controls/data/splitview/fillItemOnLeft.qml @@ -1,5 +1,5 @@ // Copyright (C) 2018 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only import QtQuick import QtQuick.Controls diff --git a/tests/auto/quickcontrols/controls/data/splitview/fillItemOnTop.qml b/tests/auto/quickcontrols/controls/data/splitview/fillItemOnTop.qml index 41ce0f386e..4d41624b7e 100644 --- a/tests/auto/quickcontrols/controls/data/splitview/fillItemOnTop.qml +++ b/tests/auto/quickcontrols/controls/data/splitview/fillItemOnTop.qml @@ -1,5 +1,5 @@ // Copyright (C) 2018 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only import QtQuick import QtQuick.Controls diff --git a/tests/auto/quickcontrols/controls/data/stackview/Rect.qml b/tests/auto/quickcontrols/controls/data/stackview/Rect.qml new file mode 100644 index 0000000000..699cef6b5d --- /dev/null +++ b/tests/auto/quickcontrols/controls/data/stackview/Rect.qml @@ -0,0 +1,8 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +import QtQuick + +Rectangle { + color: "tomato" +} diff --git a/tests/auto/quickcontrols/controls/data/tst_abstractbutton.qml b/tests/auto/quickcontrols/controls/data/tst_abstractbutton.qml index 663b152c70..bce13b37f2 100644 --- a/tests/auto/quickcontrols/controls/data/tst_abstractbutton.qml +++ b/tests/auto/quickcontrols/controls/data/tst_abstractbutton.qml @@ -1,5 +1,5 @@ // Copyright (C) 2017 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only import QtQuick import QtTest @@ -42,15 +42,56 @@ TestCase { SignalSpy { } } - function test_defaults() { + property var expectedPressSignals: [ + ["activeFocusChanged", { "activeFocus": true }], + ["pressedChanged", { "pressed": true }], + ["downChanged", { "down": true }], + "pressed" + ] + + property var expectedReleaseSignals: [ + ["pressedChanged", { "pressed": false }], + ["downChanged", { "down": false }], + "released", + "clicked" + ] + + property var expectedClickSignals + + property var expectedCheckableClickSignals: [ + ["activeFocusChanged", { "activeFocus": true }], + ["pressedChanged", { "pressed": true }], + ["downChanged", { "down": true }], + "pressed", + ["pressedChanged", { "pressed": false }], + ["downChanged", { "down": false }], + ["checkedChanged", { "checked": true }], + "toggled", + "released", + "clicked" + ] + + function initTestCase() { + // AbstractButton has TabFocus on macOS, not StrongFocus. + if (Qt.platform.os === "osx") { + expectedPressSignals.splice(0, 1) + expectedCheckableClickSignals.splice(0, 1) + } + + expectedClickSignals = [...expectedPressSignals, ...expectedReleaseSignals] + } + + function init() { failOnWarning(/.?/) + } + function test_defaults() { let control = createTemporaryObject(defaultComponent, testCase) verify(control) } function test_text() { - var control = createTemporaryObject(button, testCase); + let control = createTemporaryObject(button, testCase); verify(control); compare(control.text, ""); @@ -61,7 +102,7 @@ TestCase { } function test_baseline() { - var control = createTemporaryObject(button, testCase, {padding: 6}) + let control = createTemporaryObject(button, testCase, {padding: 6}) verify(control) compare(control.baselineOffset, 0) control.contentItem = item.createObject(control, {baselineOffset: 12}) @@ -69,7 +110,7 @@ TestCase { } function test_implicitSize() { - var control = createTemporaryObject(button, testCase) + let control = createTemporaryObject(button, testCase) verify(control) compare(control.implicitWidth, 0) @@ -96,22 +137,22 @@ TestCase { } function test_pressPoint(data) { - var control = createTemporaryObject(button, testCase, {width: 100, height: 40}) + let control = createTemporaryObject(button, testCase, {width: 100, height: 40}) verify(control) - var pressXChanges = 0 - var pressYChanges = 0 + let pressXChanges = 0 + let pressYChanges = 0 - var pressXSpy = signalSpy.createObject(control, {target: control, signalName: "pressXChanged"}) + let pressXSpy = signalSpy.createObject(control, {target: control, signalName: "pressXChanged"}) verify(pressXSpy.valid) - var pressYSpy = signalSpy.createObject(control, {target: control, signalName: "pressYChanged"}) + let pressYSpy = signalSpy.createObject(control, {target: control, signalName: "pressYChanged"}) verify(pressYSpy.valid) compare(control.pressX, 0) compare(control.pressY, 0) - var touch = data.touch ? touchEvent(control) : null + let touch = data.touch ? touchEvent(control) : null if (data.touch) touch.press(0, control, control.width / 2, control.height / 2).commit() @@ -196,10 +237,10 @@ TestCase { } function test_pressAndHold() { - var control = createTemporaryObject(button, testCase, {checkable: true}) + let control = createTemporaryObject(button, testCase, {checkable: true}) verify(control) - var pressAndHoldSpy = signalSpy.createObject(control, {target: control, signalName: "pressAndHold"}) + let pressAndHoldSpy = signalSpy.createObject(control, {target: control, signalName: "pressAndHold"}) verify(pressAndHoldSpy.valid) mousePress(control) @@ -215,8 +256,8 @@ TestCase { Item { property int lastKeyPress: -1 property int lastKeyRelease: -1 - Keys.onPressed: lastKeyPress = event.key - Keys.onReleased: lastKeyRelease = event.key + Keys.onPressed: function (event) { lastKeyPress = event.key } + Keys.onReleased: function (event) { lastKeyRelease = event.key } } } @@ -228,10 +269,10 @@ TestCase { } function test_keyEvents(data) { - var container = createTemporaryObject(keyCatcher, testCase) + let container = createTemporaryObject(keyCatcher, testCase) verify(container) - var control = button.createObject(container) + let control = button.createObject(container) verify(control) control.forceActiveFocus() @@ -245,7 +286,7 @@ TestCase { } function test_icon() { - var control = createTemporaryObject(button, testCase) + let control = createTemporaryObject(button, testCase) verify(control) compare(control.icon.name, "") compare(control.icon.source, "") @@ -253,7 +294,7 @@ TestCase { compare(control.icon.height, 0) compare(control.icon.color, "#00000000") - var iconSpy = signalSpy.createObject(control, { target: control, signalName: "iconChanged"} ) + let iconSpy = signalSpy.createObject(control, { target: control, signalName: "iconChanged"} ) verify(iconSpy.valid) control.icon.name = "test-name" @@ -322,14 +363,14 @@ TestCase { } function test_action(data) { - var control = createTemporaryObject(button, testCase) + let control = createTemporaryObject(button, testCase) verify(control) control[data.property] = data.initButton - var act = action.createObject(control) + let act = action.createObject(control) act[data.property] = data.initAction - var spy = signalSpy.createObject(control, {target: control, signalName: data.property + "Changed"}) + let spy = signalSpy.createObject(control, {target: control, signalName: data.property + "Changed"}) verify(spy.valid) // assign action @@ -362,23 +403,23 @@ TestCase { } function test_actionIcon_data() { - var data = [] + let data = [] // Save duplicating the rows by reusing them with different properties of the same type. // This means that the first loop will test icon.name and the second one will test icon.source. - var stringPropertyValueSuffixes = [ + let stringPropertyValueSuffixes = [ { propertyName: "name", valueSuffix: "IconName" }, { propertyName: "source", valueSuffix: "IconSource" } ] - for (var i = 0; i < stringPropertyValueSuffixes.length; ++i) { - var propertyName = stringPropertyValueSuffixes[i].propertyName - var valueSuffix = stringPropertyValueSuffixes[i].valueSuffix + for (let i = 0; i < stringPropertyValueSuffixes.length; ++i) { + let propertyName = stringPropertyValueSuffixes[i].propertyName + let valueSuffix = stringPropertyValueSuffixes[i].valueSuffix - var buttonPropertyValue = "Button" + valueSuffix - var buttonPropertyValue2 = "Button" + valueSuffix + "2" - var actionPropertyValue = "Action" + valueSuffix - var actionPropertyValue2 = "Action" + valueSuffix + "2" + let buttonPropertyValue = "Button" + valueSuffix + let buttonPropertyValue2 = "Button" + valueSuffix + "2" + let actionPropertyValue = "Action" + valueSuffix + let actionPropertyValue2 = "Action" + valueSuffix + "2" data.push({ tag: "implicit " + propertyName, property: propertyName, initButton: undefined, initAction: actionPropertyValue, @@ -420,19 +461,19 @@ TestCase { resetExpected: buttonPropertyValue, resetChanged: false }) } - var intPropertyNames = [ + let intPropertyNames = [ "width", "height", ] - for (i = 0; i < intPropertyNames.length; ++i) { - propertyName = intPropertyNames[i] + for (let i = 0; i < intPropertyNames.length; ++i) { + let propertyName = intPropertyNames[i] - buttonPropertyValue = 20 - buttonPropertyValue2 = 21 - actionPropertyValue = 40 - actionPropertyValue2 = 41 - var defaultValue = 0 + let buttonPropertyValue = 20 + let buttonPropertyValue2 = 21 + let actionPropertyValue = 40 + let actionPropertyValue2 = 41 + let defaultValue = 0 data.push({ tag: "implicit " + propertyName, property: propertyName, initButton: undefined, initAction: actionPropertyValue, @@ -474,12 +515,12 @@ TestCase { resetExpected: buttonPropertyValue, resetChanged: false }) } - propertyName = "color" - buttonPropertyValue = "#aa0000" - buttonPropertyValue2 = "#ff0000" - actionPropertyValue = "#0000aa" - actionPropertyValue2 = "#0000ff" - defaultValue = "#00000000" + let propertyName = "color" + let buttonPropertyValue = "#aa0000" + let buttonPropertyValue2 = "#ff0000" + let actionPropertyValue = "#0000aa" + let actionPropertyValue2 = "#0000ff" + let defaultValue = "#00000000" data.push({ tag: "implicit " + propertyName, property: propertyName, initButton: undefined, initAction: actionPropertyValue, @@ -524,14 +565,14 @@ TestCase { } function test_actionIcon(data) { - var control = createTemporaryObject(button, testCase) + let control = createTemporaryObject(button, testCase) verify(control) control.icon[data.property] = data.initButton - var act = action.createObject(control) + let act = action.createObject(control) act.icon[data.property] = data.initAction - var spy = signalSpy.createObject(control, {target: control, signalName: "iconChanged"}) + let spy = signalSpy.createObject(control, {target: control, signalName: "iconChanged"}) verify(spy.valid) // assign action @@ -580,7 +621,7 @@ TestCase { } function test_actionButton() { - var control = createTemporaryObject(actionButton, testCase) + let control = createTemporaryObject(actionButton, testCase) verify(control) // initial values @@ -590,7 +631,7 @@ TestCase { compare(control.enabled, false) compare(control.icon.name, "checked") - var textSpy = signalSpy.createObject(control, { target: control, signalName: "textChanged" }) + let textSpy = signalSpy.createObject(control, { target: control, signalName: "textChanged" }) verify(textSpy.valid) // changes via action @@ -631,7 +672,7 @@ TestCase { // setting an action while button has a particular property set // shouldn't cause a change in the button's effective property value - var secondAction = createTemporaryObject(action, testCase) + let secondAction = createTemporaryObject(action, testCase) verify(secondAction) secondAction.text = "SecondAction" control.action = secondAction @@ -639,7 +680,7 @@ TestCase { compare(textSpy.count, 2) // test setting an action whose properties aren't set - var thirdAction = createTemporaryObject(action, testCase) + let thirdAction = createTemporaryObject(action, testCase) verify(thirdAction) control.action = thirdAction compare(control.text, "Button") @@ -657,7 +698,7 @@ TestCase { } function test_checkable_button() { - var control = createTemporaryObject(checkableButton, testCase) + let control = createTemporaryObject(checkableButton, testCase) verify(control) control.checked = false control.forceActiveFocus() @@ -681,9 +722,9 @@ TestCase { compare(control.action.checked, false) compare(control.checked, false) - var checkedSpy = signalSpy.createObject(control, {target: control.action, signalName: "checkedChanged"}) - var toggledSpy = signalSpy.createObject(control, {target: control, signalName: "toggled"}) - var actionToggledSpy = signalSpy.createObject(control, {target: control.action, signalName: "toggled"}) + let checkedSpy = signalSpy.createObject(control, {target: control.action, signalName: "checkedChanged"}) + let toggledSpy = signalSpy.createObject(control, {target: control, signalName: "toggled"}) + let actionToggledSpy = signalSpy.createObject(control, {target: control.action, signalName: "toggled"}) verify(checkedSpy.valid) verify(toggledSpy.valid) @@ -723,16 +764,16 @@ TestCase { } function test_trigger(data) { - var control = createTemporaryObject(actionButton, testCase, {"action.enabled": data.action, "enabled": data.button}) + let control = createTemporaryObject(actionButton, testCase, {"action.enabled": data.action, "enabled": data.button}) verify(control) compare(control.enabled, data.button) compare(control.action.enabled, data.action) - var buttonSpy = signalSpy.createObject(control, {target: control, signalName: "clicked"}) + let buttonSpy = signalSpy.createObject(control, {target: control, signalName: "clicked"}) verify(buttonSpy.valid) - var actionSpy = signalSpy.createObject(control, {target: control.action, signalName: "triggered"}) + let actionSpy = signalSpy.createObject(control, {target: control.action, signalName: "triggered"}) verify(actionSpy.valid) if (data.click) @@ -748,13 +789,13 @@ TestCase { if (Qt.platform.os === "osx" || Qt.platform.os === "macos") skip("Mnemonics are not used on macOS") - var control = createTemporaryObject(button, testCase) + let control = createTemporaryObject(button, testCase) verify(control) control.text = "&Hello" compare(control.text, "&Hello") - var clickSpy = signalSpy.createObject(control, {target: control, signalName: "clicked"}) + let clickSpy = signalSpy.createObject(control, {target: control, signalName: "clicked"}) verify(clickSpy.valid) keyClick(Qt.Key_H, Qt.AltModifier) @@ -789,7 +830,7 @@ TestCase { control.text = undefined control.action = action.createObject(control, {text: "&Action"}) - var actionSpy = signalSpy.createObject(control, {target: control.action, signalName: "triggered"}) + let actionSpy = signalSpy.createObject(control, {target: control.action, signalName: "triggered"}) verify(actionSpy.valid) keyClick(Qt.Key_A, Qt.AltModifier) @@ -814,12 +855,12 @@ TestCase { } function test_actionGroup() { - var group = createTemporaryObject(actionGroup, testCase) + let group = createTemporaryObject(actionGroup, testCase) verify(group) - var button1 = createTemporaryObject(button, testCase, {action: group.actions[0], width: 10, height: 10}) - var button2 = createTemporaryObject(button, testCase, {action: group.actions[1], width: 10, height: 10, y: 10}) - var button3 = createTemporaryObject(button, testCase, {action: group.actions[2], width: 10, height: 10, y: 20}) + let button1 = createTemporaryObject(button, testCase, {action: group.actions[0], width: 10, height: 10}) + let button2 = createTemporaryObject(button, testCase, {action: group.actions[1], width: 10, height: 10, y: 10}) + let button3 = createTemporaryObject(button, testCase, {action: group.actions[2], width: 10, height: 10, y: 20}) verify(button1) compare(button1.checked, true) @@ -846,10 +887,10 @@ TestCase { } function test_clickedAfterLongPress() { - var control = createTemporaryObject(button, testCase, { text: "Hello" }) + let control = createTemporaryObject(button, testCase, { text: "Hello" }) verify(control) - var clickedSpy = signalSpy.createObject(control, { target: control, signalName: "clicked" }) + let clickedSpy = signalSpy.createObject(control, { target: control, signalName: "clicked" }) verify(clickedSpy.valid) mousePress(control) @@ -967,5 +1008,172 @@ TestCase { verify(control) verify(!control.checkable) - } + } + + function test_rightMouseButton() { + let control = createTemporaryObject(button, testCase) + verify(control) + + let pressedSpy = signalSpy.createObject(control, { target: control, signalName: "pressed" }) + verify(pressedSpy.valid) + + let releasedSpy = signalSpy.createObject(control, { target: control, signalName: "released" }) + verify(releasedSpy.valid) + + let clickedSpy = signalSpy.createObject(control, { target: control, signalName: "clicked" }) + verify(clickedSpy.valid) + + // button should not react on the right mouse button by defualt + mousePress(control, control.width / 2, control.height / 2, Qt.RightButton) + mouseRelease(control, control.width / 2, control.height / 2, Qt.RightButton) + + compare(pressedSpy.count, 0) + compare(releasedSpy.count, 0) + compare(clickedSpy.count, 0) + + // QTBUG-116289 - adding a HoverHandler into the button should not affect the handling of the right mouse button + let hoverHandler = createTemporaryQmlObject("import QtQuick; HoverHandler {}", control) + verify(hoverHandler) + compare(hoverHandler.target, control) + + mousePress(control, control.width / 2, control.height / 2, Qt.RightButton) + mouseRelease(control, control.width / 2, control.height / 2, Qt.RightButton) + + compare(pressedSpy.count, 0) + compare(releasedSpy.count, 0) + compare(clickedSpy.count, 0) + } + + Component { + id: signalSequenceSpy + SignalSequenceSpy { + // List all signals, even ones we might not be interested in for a particular test, + // so that it can catch unwanted ones and fail the test. + signals: ["pressed", "released", "canceled", "clicked", "toggled", "doubleClicked", + "pressedChanged", "downChanged", "checkedChanged", "activeFocusChanged"] + } + } + + function test_click() { + let control = createTemporaryObject(button, testCase) + verify(control) + + let sequenceSpy = signalSequenceSpy.createObject(control, { target: control }) + sequenceSpy.expectedSequence = testCase.expectedClickSignals + control.click() + verify(sequenceSpy.success) + } + + function test_clickCheckableButton() { + let control = createTemporaryObject(button, testCase, { checkable: true }) + verify(control) + + let sequenceSpy = signalSequenceSpy.createObject(control, { target: control }) + sequenceSpy.expectedSequence = testCase.expectedCheckableClickSignals + control.click() + verify(sequenceSpy.success) + } + + function test_animateClick() { + let control = createTemporaryObject(button, testCase) + verify(control) + + let sequenceSpy = signalSequenceSpy.createObject(control, { target: control }) + sequenceSpy.expectedSequence = testCase.expectedClickSignals + control.animateClick() + tryVerify(() => { return sequenceSpy.success }, 1000) + } + + function test_animateClickCheckableButton() { + let control = createTemporaryObject(button, testCase, { checkable: true }) + verify(control) + + let sequenceSpy = signalSequenceSpy.createObject(control, { target: control }) + sequenceSpy.expectedSequence = testCase.expectedCheckableClickSignals + control.animateClick() + tryVerify(() => { return sequenceSpy.success }, 1000) + } + + function test_animateClickTwice() { + let control = createTemporaryObject(button, testCase) + verify(control) + + let sequenceSpy = signalSequenceSpy.createObject(control, { target: control }) + sequenceSpy.expectedSequence = testCase.expectedPressSignals + // Check that calling it again before it finishes works as expected. + control.animateClick() + verify(sequenceSpy.success) + // Let the timer progress a bit. + wait(0) + sequenceSpy.expectedSequence = testCase.expectedReleaseSignals + control.animateClick() + tryVerify(() => { return sequenceSpy.success }, 1000) + } + + function test_clickOnDisabledButton() { + let control = createTemporaryObject(button, testCase, { enabled: false }) + verify(control) + + let sequenceSpy = signalSequenceSpy.createObject(control, { target: control }) + sequenceSpy.expectedSequence = [] + control.click() + verify(sequenceSpy.success) + } + + function test_animateClickOnDisabledButton() { + let control = createTemporaryObject(button, testCase, { enabled: false }) + verify(control) + + let sequenceSpy = signalSequenceSpy.createObject(control, { target: control }) + sequenceSpy.expectedSequence = [] + control.animateClick() + verify(sequenceSpy.success) + } + + Component { + id: destroyOnPressButtonComponent + + AbstractButton { + width: 100 + height: 50 + + onPressed: destroy(this) + } + } + + function test_clickDestroyOnPress() { + let control = createTemporaryObject(destroyOnPressButtonComponent, testCase) + verify(control) + + // Parent it to the testCase, otherwise it will be destroyed when the control is. + let destructionSpy = createTemporaryObject(signalSpy, testCase, + { target: control.Component, signalName: "destruction" }) + verify(destructionSpy.valid) + + let sequenceSpy = signalSequenceSpy.createObject(control, { target: control }) + sequenceSpy.expectedSequence = testCase.expectedClickSignals + // Shouldn't crash, etc. Note that destroy() isn't synchronous, and so + // the destruction will happen after the release. + control.click() + verify(sequenceSpy.success) + tryCompare(destructionSpy, "count", 1) + } + + function test_animateClickDestroyOnPress() { + let control = createTemporaryObject(destroyOnPressButtonComponent, testCase) + verify(control) + + // Parent it to the testCase, otherwise it will be destroyed when the control is. + let destructionSpy = createTemporaryObject(signalSpy, testCase, + { target: control.Component, signalName: "destruction" }) + verify(destructionSpy.valid) + + let sequenceSpy = signalSequenceSpy.createObject(control, { target: control }) + sequenceSpy.expectedSequence = testCase.expectedPressSignals + // Shouldn't crash, etc. Note that destroy() isn't synchronous, but it is processed + // on the next frame, so should always come before the release's 100 ms delay. + control.animateClick() + verify(sequenceSpy.success) + tryCompare(destructionSpy, "count", 1) + } } diff --git a/tests/auto/quickcontrols/controls/data/tst_action.qml b/tests/auto/quickcontrols/controls/data/tst_action.qml index 845a6507af..f2b7a8674d 100644 --- a/tests/auto/quickcontrols/controls/data/tst_action.qml +++ b/tests/auto/quickcontrols/controls/data/tst_action.qml @@ -1,5 +1,5 @@ // Copyright (C) 2017 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only import QtQuick import QtTest @@ -24,18 +24,20 @@ TestCase { SignalSpy { } } - function test_empty() { + function init() { failOnWarning(/.?/) + } + function test_empty() { let control = createTemporaryObject(component, testCase) verify(control) } function test_enabled() { - var action = createTemporaryObject(component, testCase) + let action = createTemporaryObject(component, testCase) verify(action) - var spy = createTemporaryObject(signalSpy, testCase, {target: action, signalName: "triggered"}) + let spy = createTemporaryObject(signalSpy, testCase, {target: action, signalName: "triggered"}) verify(spy.valid) action.trigger() @@ -53,24 +55,34 @@ TestCase { Component { id: buttonAndMenu Item { + objectName: "container" + property alias button: button property alias menu: menu property alias menuItem: menuItem property alias action: sharedAction property var lastSource + Action { id: sharedAction + objectName: "sharedAction" text: "Shared" shortcut: "Ctrl+B" onTriggered: (source) => lastSource = source } Button { id: button + objectName: "button" action: sharedAction + Menu { id: menu + objectName: "menu" + contentItem.objectName: "menuContentItem" + MenuItem { id: menuItem + objectName: "menuItem" action: sharedAction } } @@ -79,7 +91,7 @@ TestCase { } function test_shared() { - var container = createTemporaryObject(buttonAndMenu, testCase) + let container = createTemporaryObject(buttonAndMenu, testCase) verify(container) keyClick(Qt.Key_B, Qt.ControlModifier) @@ -116,10 +128,10 @@ TestCase { } function test_repeater() { - var container = createTemporaryObject(actionAndRepeater, testCase) + let container = createTemporaryObject(actionAndRepeater, testCase) verify(container) - var spy = signalSpy.createObject(container, {target: container.action, signalName: "triggered"}) + let spy = signalSpy.createObject(container, {target: container.action, signalName: "triggered"}) verify(spy.valid) keyClick(Qt.Key_A, Qt.ControlModifier) @@ -150,7 +162,7 @@ TestCase { } function test_shortcutBinding() { - var container = createTemporaryObject(shortcutBinding, testCase); + let container = createTemporaryObject(shortcutBinding, testCase); verify(container) compare(container.indirect.nativeText, container.direct.nativeText); } @@ -178,7 +190,7 @@ TestCase { function test_shortcutCleanup() { { - var container = createTemporaryObject(shortcutCleanup, testCase); + let container = createTemporaryObject(shortcutCleanup, testCase); verify(container) container.action.shortcut = "Delete" container.menu.open() diff --git a/tests/auto/quickcontrols/controls/data/tst_actiongroup.qml b/tests/auto/quickcontrols/controls/data/tst_actiongroup.qml index 4b5fdc7d65..dc17d554a4 100644 --- a/tests/auto/quickcontrols/controls/data/tst_actiongroup.qml +++ b/tests/auto/quickcontrols/controls/data/tst_actiongroup.qml @@ -1,5 +1,5 @@ // Copyright (C) 2017 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only import QtQuick import QtTest @@ -37,8 +37,12 @@ TestCase { SignalSpy { } } + function init() { + failOnWarning(/.?/) + } + function test_null() { - var group = createTemporaryObject(actionGroup, testCase) + let group = createTemporaryObject(actionGroup, testCase) verify(group) group.addAction(null) @@ -51,9 +55,7 @@ TestCase { } function test_defaults() { - failOnWarning(/.?/) - - var group = createTemporaryObject(actionGroup, testCase) + let group = createTemporaryObject(actionGroup, testCase) verify(group) compare(group.actions.length, 0) compare(group.checkedAction, null) @@ -61,16 +63,16 @@ TestCase { } function test_current() { - var group = createTemporaryObject(actionGroup, testCase) + let group = createTemporaryObject(actionGroup, testCase) verify(group) - var checkedActionSpy = createTemporaryObject(signalSpy, testCase, {target: group, signalName: "checkedActionChanged"}) + let checkedActionSpy = createTemporaryObject(signalSpy, testCase, {target: group, signalName: "checkedActionChanged"}) verify(checkedActionSpy.valid) verify(!group.checkedAction) - var action1 = createTemporaryObject(action, testCase, {checked: true}) - var action2 = createTemporaryObject(action, testCase, {checked: false}) - var action3 = createTemporaryObject(action, testCase, {checked: true, objectName: "3"}) + let action1 = createTemporaryObject(action, testCase, {checked: true}) + let action2 = createTemporaryObject(action, testCase, {checked: false}) + let action3 = createTemporaryObject(action, testCase, {checked: true, objectName: "3"}) // add checked group.addAction(action1) @@ -130,17 +132,17 @@ TestCase { } function test_actions() { - var group = createTemporaryObject(actionGroup, testCase) + let group = createTemporaryObject(actionGroup, testCase) verify(group) - var actionsSpy = createTemporaryObject(signalSpy, testCase, {target: group, signalName: "actionsChanged"}) + let actionsSpy = createTemporaryObject(signalSpy, testCase, {target: group, signalName: "actionsChanged"}) verify(actionsSpy.valid) compare(group.actions.length, 0) compare(group.checkedAction, null) - var action1 = createTemporaryObject(action, testCase, {checked: true}) - var action2 = createTemporaryObject(action, testCase, {checked: false}) + let action1 = createTemporaryObject(action, testCase, {checked: true}) + let action2 = createTemporaryObject(action, testCase, {checked: false}) group.actions = [action1, action2] compare(group.actions.length, 2) @@ -149,7 +151,7 @@ TestCase { compare(group.checkedAction, action1) compare(actionsSpy.count, 2) - var action3 = createTemporaryObject(action, testCase, {checked: true}) + let action3 = createTemporaryObject(action, testCase, {checked: true}) group.addAction(action3) compare(group.actions.length, 3) @@ -173,7 +175,7 @@ TestCase { } function test_declarative() { - var group = createTemporaryObject(declarativeGroup, testCase) + let group = createTemporaryObject(declarativeGroup, testCase) verify(group) compare(group.actions.length, 3) @@ -190,14 +192,14 @@ TestCase { } function test_triggered(data) { - var group = createTemporaryObject(actionGroup, testCase, {exclusive: data.exclusive}) + let group = createTemporaryObject(actionGroup, testCase, {exclusive: data.exclusive}) verify(group) - var triggeredSpy = createTemporaryObject(signalSpy, testCase, {target: group, signalName: "triggered"}) + let triggeredSpy = createTemporaryObject(signalSpy, testCase, {target: group, signalName: "triggered"}) verify(triggeredSpy.valid) - var action1 = createTemporaryObject(action, testCase) - var action2 = createTemporaryObject(action, testCase) + let action1 = createTemporaryObject(action, testCase) + let action2 = createTemporaryObject(action, testCase) group.addAction(action1) group.addAction(action2) @@ -222,7 +224,7 @@ TestCase { } function test_attached() { - var container = createTemporaryObject(attachedGroup, testCase) + let container = createTemporaryObject(attachedGroup, testCase) verify(container) verify(!container.group.checkedAction) @@ -247,13 +249,13 @@ TestCase { } function test_actionDestroyed() { - var group = createTemporaryObject(actionGroup, testCase) + let group = createTemporaryObject(actionGroup, testCase) verify(group) - var actionsSpy = createTemporaryObject(signalSpy, testCase, {target: group, signalName: "actionsChanged"}) + let actionsSpy = createTemporaryObject(signalSpy, testCase, {target: group, signalName: "actionsChanged"}) verify(actionsSpy.valid) - var action1 = createTemporaryObject(action, testCase, {objectName: "action1", checked: true}) + let action1 = createTemporaryObject(action, testCase, {objectName: "action1", checked: true}) group.addAction(action1) compare(group.actions.length, 1) @@ -269,15 +271,15 @@ TestCase { } function test_nonExclusive() { - var group = createTemporaryObject(nonExclusiveGroup, testCase) + let group = createTemporaryObject(nonExclusiveGroup, testCase) verify(group) - var action1 = createTemporaryObject(action, testCase, {checked: true}) + let action1 = createTemporaryObject(action, testCase, {checked: true}) group.addAction(action1) compare(action1.checked, true) compare(group.checkedAction, null) - var action2 = createTemporaryObject(action, testCase, {checked: true}) + let action2 = createTemporaryObject(action, testCase, {checked: true}) group.addAction(action2) compare(action1.checked, true) compare(action2.checked, true) @@ -305,18 +307,18 @@ TestCase { } function test_enabled() { - var group = createTemporaryObject(actionGroup, testCase) + let group = createTemporaryObject(actionGroup, testCase) verify(group) compare(group.enabled, true) - var action1 = createTemporaryObject(action, testCase) - var action2 = createTemporaryObject(action, testCase) + let action1 = createTemporaryObject(action, testCase) + let action2 = createTemporaryObject(action, testCase) compare(action1.enabled, true) compare(action2.enabled, true) - var action1Spy = createTemporaryObject(signalSpy, testCase, {target: action1, signalName: "enabledChanged"}) - var action2Spy = createTemporaryObject(signalSpy, testCase, {target: action2, signalName: "enabledChanged"}) + let action1Spy = createTemporaryObject(signalSpy, testCase, {target: action1, signalName: "enabledChanged"}) + let action2Spy = createTemporaryObject(signalSpy, testCase, {target: action2, signalName: "enabledChanged"}) verify(action1Spy.valid && action2Spy.valid) group.addAction(action1) @@ -352,4 +354,130 @@ TestCase { compare(action2Spy.count, 2) compare(action2Spy.signalArguments[1][0], true) } + + Component { + id: checkBoxes + Item { + property ActionGroup group: ActionGroup { id: group } + property CheckBox control1: CheckBox { action: Action { ActionGroup.group: group } } + property CheckBox control2: CheckBox { action: Action { ActionGroup.group: group } } + property CheckBox control3: CheckBox { action: Action { ActionGroup.group: group } } + } + } + + Component { + id: radioButtons + Item { + property ActionGroup group: ActionGroup { id: group } + property RadioButton control1: RadioButton { action: Action { ActionGroup.group: group } } + property RadioButton control2: RadioButton { action: Action { ActionGroup.group: group } } + property RadioButton control3: RadioButton { action: Action { ActionGroup.group: group } } + } + } + + Component { + id: switches + Item { + property ActionGroup group: ActionGroup { id: group } + property Switch control1: Switch { action: Action { ActionGroup.group: group } } + property Switch control2: Switch { action: Action { ActionGroup.group: group } } + property Switch control3: Switch { action: Action { ActionGroup.group: group } } + } + } + + function test_controls_data() { + return [ + { tag: "CheckBox", component: checkBoxes }, + { tag: "RadioButton", component: radioButtons }, + { tag: "Switch", component: switches }, + ] + } + + function test_controls(data) { + let container = createTemporaryObject(data.component, testCase) + verify(container) + + verify(!container.group.checkedAction) + + container.control1.checked = true + compare(container.group.checkedAction, container.control1.action) + compare(container.control1.checked, true) + compare(container.control2.checked, false) + compare(container.control3.checked, false) + + container.control2.checked = true + compare(container.group.checkedAction, container.control2.action) + compare(container.control1.checked, false) + compare(container.control2.checked, true) + compare(container.control3.checked, false) + + container.control3.checked = true + compare(container.group.checkedAction, container.control3.action) + compare(container.control1.checked, false) + compare(container.control2.checked, false) + compare(container.control3.checked, true) + } + + Component { + id: exclusiveMenus + Column { + property ActionGroup group: ActionGroup { id: group } + property alias control1: control1 + property alias control2: control2 + property alias control3: control3 + MenuItem { + id: control1 + action: Action { + checkable: true + ActionGroup.group: group + } + } + MenuItem { + id: control2 + action: Action { + checkable: true + ActionGroup.group: group + } + } + MenuItem { + id: control3 + action: Action { + checkable: true + ActionGroup.group: group + } + } + } + } + + function test_exclusiveActionButtons() { + const container = createTemporaryObject(exclusiveMenus, testCase) + verify(container) + + verify(!container.group.checkedAction) + + mouseClick(container.control1) + compare(container.group.checkedAction, container.control1.action) + compare(container.control1.checked, true) + compare(container.control2.checked, false) + compare(container.control3.checked, false) + + mouseClick(container.control2) + compare(container.group.checkedAction, container.control2.action) + compare(container.control1.checked, false) + compare(container.control2.checked, true) + compare(container.control3.checked, false) + + mouseClick(container.control3) + compare(container.group.checkedAction, container.control3.action) + compare(container.control1.checked, false) + compare(container.control2.checked, false) + compare(container.control3.checked, true) + + // here comes the tricky part: clicking on checked control must not uncheck it + mouseClick(container.control3) + compare(container.group.checkedAction, container.control3.action) + compare(container.control1.checked, false) + compare(container.control2.checked, false) + compare(container.control3.checked, true) + } } diff --git a/tests/auto/quickcontrols/controls/data/tst_busyindicator.qml b/tests/auto/quickcontrols/controls/data/tst_busyindicator.qml index a50fd1bfab..001b0c474f 100644 --- a/tests/auto/quickcontrols/controls/data/tst_busyindicator.qml +++ b/tests/auto/quickcontrols/controls/data/tst_busyindicator.qml @@ -1,5 +1,5 @@ // Copyright (C) 2017 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only import QtQuick import QtTest @@ -22,17 +22,26 @@ TestCase { id: mouseArea MouseArea { } } - - function test_defaults() { + + Component { + id: busyIndicatorInItem + Item { + BusyIndicator { } + } + } + + function init() { failOnWarning(/.?/) + } + function test_defaults() { let control = createTemporaryObject(busyIndicator, testCase) verify(control) compare(control.running, true) } function test_running() { - var control = createTemporaryObject(busyIndicator, testCase) + let control = createTemporaryObject(busyIndicator, testCase) verify(control) compare(control.running, true) @@ -42,10 +51,10 @@ TestCase { // QTBUG-61785 function test_mouseArea() { - var ma = createTemporaryObject(mouseArea, testCase, {width: testCase.width, height: testCase.height}) + let ma = createTemporaryObject(mouseArea, testCase, {width: testCase.width, height: testCase.height}) verify(ma) - var control = busyIndicator.createObject(ma, {width: testCase.width, height: testCase.height}) + let control = busyIndicator.createObject(ma, {width: testCase.width, height: testCase.height}) verify(control) mousePress(control) @@ -54,11 +63,23 @@ TestCase { mouseRelease(control) verify(!ma.pressed) - var touch = touchEvent(control) + let touch = touchEvent(control) touch.press(0, control).commit() verify(ma.pressed) touch.release(0, control).commit() verify(!ma.pressed) } + + // QTBUG-108808 + function test_visibility() { + let control = createTemporaryObject(busyIndicatorInItem, testCase, {visible: false}) + verify(control) + + let invisibleImage = grabImage(control) + control.visible = true + let visibleImage = grabImage(control) + + verify(!invisibleImage.equals(visibleImage)) + } } diff --git a/tests/auto/quickcontrols/controls/data/tst_button.qml b/tests/auto/quickcontrols/controls/data/tst_button.qml index 9ddfa0885d..eaf38610cc 100644 --- a/tests/auto/quickcontrols/controls/data/tst_button.qml +++ b/tests/auto/quickcontrols/controls/data/tst_button.qml @@ -1,9 +1,10 @@ // Copyright (C) 2017 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only import QtQuick import QtTest import QtQuick.Controls +import Qt.test.controls TestCase { id: testCase @@ -30,9 +31,11 @@ TestCase { SignalSpy { } } - function test_defaults() { + function init() { failOnWarning(/.?/) + } + function test_defaults() { let control = createTemporaryObject(button, testCase) verify(control) compare(control.highlighted, false) @@ -40,7 +43,7 @@ TestCase { } function test_text() { - var control = createTemporaryObject(button, testCase) + let control = createTemporaryObject(button, testCase) verify(control) compare(control.text, "") @@ -51,10 +54,10 @@ TestCase { } function test_mouse() { - var control = createTemporaryObject(button, testCase) + let control = createTemporaryObject(button, testCase) verify(control) - var sequenceSpy = signalSequenceSpy.createObject(control, {target: control}) + let sequenceSpy = signalSequenceSpy.createObject(control, {target: control}) // click sequenceSpy.expectedSequence = [["pressedChanged", { "pressed": true }], @@ -120,11 +123,11 @@ TestCase { } function test_touch() { - var control = createTemporaryObject(button, testCase) + let control = createTemporaryObject(button, testCase) verify(control) - var touch = touchEvent(control) - var sequenceSpy = signalSequenceSpy.createObject(control, {target: control}) + let touch = touchEvent(control) + let sequenceSpy = signalSequenceSpy.createObject(control, {target: control}) // click sequenceSpy.expectedSequence = [["pressedChanged", { "pressed": true }], @@ -163,15 +166,15 @@ TestCase { } function test_multiTouch() { - var control1 = createTemporaryObject(button, testCase) + let control1 = createTemporaryObject(button, testCase) verify(control1) - var pressedCount1 = 0 + let pressedCount1 = 0 - var pressedSpy1 = signalSpy.createObject(control1, {target: control1, signalName: "pressedChanged"}) + let pressedSpy1 = signalSpy.createObject(control1, {target: control1, signalName: "pressedChanged"}) verify(pressedSpy1.valid) - var touch = touchEvent(control1) + let touch = touchEvent(control1) touch.press(0, control1, 0, 0).commit().move(0, control1, control1.width - 1, control1.height - 1).commit() compare(pressedSpy1.count, ++pressedCount1) @@ -185,12 +188,12 @@ TestCase { compare(pressedSpy1.count, pressedCount1) compare(control1.pressed, true) - var control2 = createTemporaryObject(button, testCase, {y: control1.height}) + let control2 = createTemporaryObject(button, testCase, {y: control1.height}) verify(control2) - var pressedCount2 = 0 + let pressedCount2 = 0 - var pressedSpy2 = signalSpy.createObject(control2, {target: control2, signalName: "pressedChanged"}) + let pressedSpy2 = signalSpy.createObject(control2, {target: control2, signalName: "pressedChanged"}) verify(pressedSpy2.valid) // press the second button @@ -213,13 +216,13 @@ TestCase { } function test_keys() { - var control = createTemporaryObject(button, testCase) + let control = createTemporaryObject(button, testCase) verify(control) control.forceActiveFocus() verify(control.activeFocus) - var sequenceSpy = signalSequenceSpy.createObject(control, {target: control}) + let sequenceSpy = signalSequenceSpy.createObject(control, {target: control}) // click sequenceSpy.expectedSequence = [["pressedChanged", { "pressed": true }], @@ -236,8 +239,8 @@ TestCase { sequenceSpy.expectedSequence = [] // Not testing Key_Enter and Key_Return because QGnomeTheme uses them for // pressing buttons and the CI uses the QGnomeTheme platform theme. - var keys = [Qt.Key_Escape, Qt.Key_Tab] - for (var i = 0; i < keys.length; ++i) { + let keys = [Qt.Key_Escape, Qt.Key_Tab] + for (let i = 0; i < keys.length; ++i) { sequenceSpy.reset() keyClick(keys[i]) verify(sequenceSpy.success) @@ -249,7 +252,7 @@ TestCase { } function test_autoRepeat() { - var control = createTemporaryObject(button, testCase) + let control = createTemporaryObject(button, testCase) verify(control) compare(control.autoRepeat, false) @@ -259,11 +262,11 @@ TestCase { control.forceActiveFocus() verify(control.activeFocus) - var clickSpy = signalSpy.createObject(control, {target: control, signalName: "clicked"}) + let clickSpy = signalSpy.createObject(control, {target: control, signalName: "clicked"}) verify(clickSpy.valid) - var pressSpy = signalSpy.createObject(control, {target: control, signalName: "pressed"}) + let pressSpy = signalSpy.createObject(control, {target: control, signalName: "pressed"}) verify(pressSpy.valid) - var releaseSpy = signalSpy.createObject(control, {target: control, signalName: "released"}) + let releaseSpy = signalSpy.createObject(control, {target: control, signalName: "released"}) verify(releaseSpy.valid) // auto-repeat mouse click @@ -333,18 +336,18 @@ TestCase { } function test_baseline() { - var control = createTemporaryObject(button, testCase) + let control = createTemporaryObject(button, testCase) verify(control) compare(control.baselineOffset, control.contentItem.y + control.contentItem.baselineOffset) } function test_checkable() { - var control = createTemporaryObject(button, testCase) + let control = createTemporaryObject(button, testCase) verify(control) verify(control.hasOwnProperty("checkable")) verify(!control.checkable) - var sequenceSpy = signalSequenceSpy.createObject(control, {target: control}) + let sequenceSpy = signalSequenceSpy.createObject(control, {target: control}) sequenceSpy.expectedSequence = [["pressedChanged", { "pressed": true }], ["downChanged", { "down": true }], @@ -386,7 +389,7 @@ TestCase { } function test_highlighted() { - var control = createTemporaryObject(button, testCase) + let control = createTemporaryObject(button, testCase) verify(control) verify(!control.highlighted) @@ -395,11 +398,11 @@ TestCase { } function test_spacing() { - var control = createTemporaryObject(button, testCase, { text: "Some long, long, long text" }) + let control = createTemporaryObject(button, testCase, { text: "Some long, long, long text" }) verify(control) verify(control.contentItem.implicitWidth + control.leftPadding + control.rightPadding > control.background.implicitWidth) - var textLabel = findChild(control.contentItem, "label") + let textLabel = findChild(control.contentItem, "label") verify(textLabel) // The implicitWidth of the IconLabel that all buttons use as their contentItem @@ -428,7 +431,7 @@ TestCase { } function test_display(data) { - var control = createTemporaryObject(button, testCase, { + let control = createTemporaryObject(button, testCase, { text: "Button", display: data.display, "icon.source": "qrc:/qt-project.org/imports/QtQuick/Controls/Basic/images/check.png", @@ -437,8 +440,8 @@ TestCase { verify(control) compare(control.icon.source, "qrc:/qt-project.org/imports/QtQuick/Controls/Basic/images/check.png") - var iconImage = findChild(control.contentItem, "image") - var textLabel = findChild(control.contentItem, "label") + let iconImage = findChild(control.contentItem, "image") + let textLabel = findChild(control.contentItem, "label") switch (control.display) { case Button.IconOnly: @@ -446,12 +449,20 @@ TestCase { verify(!textLabel) compare(iconImage.x, (control.availableWidth - iconImage.width) / 2) compare(iconImage.y, (control.availableHeight - iconImage.height) / 2) + if (StyleInfo.styleName === "Material") { + compare(control.leftPadding, Material.buttonLeftPadding(false, true)) + compare(control.rightPadding, Material.buttonRightPadding(false, true, false)) + } break; case Button.TextOnly: verify(!iconImage) verify(textLabel) compare(textLabel.x, (control.availableWidth - textLabel.width) / 2) compare(textLabel.y, (control.availableHeight - textLabel.height) / 2) + if (StyleInfo.styleName === "Material") { + compare(control.leftPadding, Material.buttonLeftPadding(false, false)) + compare(control.rightPadding, Material.buttonRightPadding(false, false, true)) + } break; case Button.TextUnderIcon: verify(iconImage) @@ -459,6 +470,10 @@ TestCase { compare(iconImage.x, (control.availableWidth - iconImage.width) / 2) compare(textLabel.x, (control.availableWidth - textLabel.width) / 2) verify(iconImage.y < textLabel.y) + if (StyleInfo.styleName === "Material") { + compare(control.leftPadding, Material.buttonLeftPadding(false, true)) + compare(control.rightPadding, Material.buttonRightPadding(false, true, true)) + } break; case Button.TextBesideIcon: verify(iconImage) @@ -469,6 +484,10 @@ TestCase { verify(iconImage.x < textLabel.x) compare(iconImage.y, (control.availableHeight - iconImage.height) / 2) compare(textLabel.y, (control.availableHeight - textLabel.height) / 2) + if (StyleInfo.styleName === "Material") { + compare(control.leftPadding, Material.buttonLeftPadding(false, true)) + compare(control.rightPadding, Material.buttonRightPadding(false, true, true)) + } break; } } diff --git a/tests/auto/quickcontrols/controls/data/tst_buttongroup.qml b/tests/auto/quickcontrols/controls/data/tst_buttongroup.qml index 2ae86d1737..c628a5cb02 100644 --- a/tests/auto/quickcontrols/controls/data/tst_buttongroup.qml +++ b/tests/auto/quickcontrols/controls/data/tst_buttongroup.qml @@ -1,5 +1,5 @@ // Copyright (C) 2017 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only import QtQuick import QtTest @@ -28,14 +28,6 @@ TestCase { SignalSpy { } } - function test_null() { - var group = createTemporaryObject(buttonGroup, testCase) - verify(group) - - group.addButton(null) - group.removeButton(null) - } - Component { id: button Button { } @@ -46,10 +38,12 @@ TestCase { QtObject { } } - function test_defaults() { + function init() { failOnWarning(/.?/) + } - var group = createTemporaryObject(buttonGroup, testCase) + function test_defaults() { + let group = createTemporaryObject(buttonGroup, testCase) verify(group) compare(group.buttons.length, 0) compare(group.checkedButton, null) @@ -57,17 +51,25 @@ TestCase { compare(group.checkState, Qt.Unchecked) } + function test_null() { + let group = createTemporaryObject(buttonGroup, testCase) + verify(group) + + group.addButton(null) + group.removeButton(null) + } + function test_current() { - var group = createTemporaryObject(buttonGroup, testCase) + let group = createTemporaryObject(buttonGroup, testCase) verify(group) - var checkedButtonSpy = createTemporaryObject(signalSpy, testCase, {target: group, signalName: "checkedButtonChanged"}) + let checkedButtonSpy = createTemporaryObject(signalSpy, testCase, {target: group, signalName: "checkedButtonChanged"}) verify(checkedButtonSpy.valid) verify(!group.checkedButton) - var button1 = createTemporaryObject(button, testCase, {checked: true}) - var button2 = createTemporaryObject(button, testCase, {checked: false}) - var button3 = createTemporaryObject(button, testCase, {checked: true, objectName: "3"}) + let button1 = createTemporaryObject(button, testCase, {checked: true}) + let button2 = createTemporaryObject(button, testCase, {checked: false}) + let button3 = createTemporaryObject(button, testCase, {checked: true, objectName: "3"}) // add checked group.addButton(button1) @@ -127,17 +129,17 @@ TestCase { } function test_buttons() { - var group = createTemporaryObject(buttonGroup, testCase) + let group = createTemporaryObject(buttonGroup, testCase) verify(group) - var buttonsSpy = createTemporaryObject(signalSpy, testCase, {target: group, signalName: "buttonsChanged"}) + let buttonsSpy = createTemporaryObject(signalSpy, testCase, {target: group, signalName: "buttonsChanged"}) verify(buttonsSpy.valid) compare(group.buttons.length, 0) compare(group.checkedButton, null) - var button1 = createTemporaryObject(button, testCase, {checked: true}) - var button2 = createTemporaryObject(button, testCase, {checked: false}) + let button1 = createTemporaryObject(button, testCase, {checked: true}) + let button2 = createTemporaryObject(button, testCase, {checked: false}) group.buttons = [button1, button2] compare(group.buttons.length, 2) @@ -146,7 +148,7 @@ TestCase { compare(group.checkedButton, button1) compare(buttonsSpy.count, 2) - var button3 = createTemporaryObject(button, testCase, {checked: true}) + let button3 = createTemporaryObject(button, testCase, {checked: true}) group.addButton(button3) compare(group.buttons.length, 3) @@ -177,14 +179,14 @@ TestCase { } function test_clicked(data) { - var group = createTemporaryObject(buttonGroup, testCase, {exclusive: data.exclusive}) + let group = createTemporaryObject(buttonGroup, testCase, {exclusive: data.exclusive}) verify(group) - var clickedSpy = createTemporaryObject(signalSpy, testCase, {target: group, signalName: "clicked"}) + let clickedSpy = createTemporaryObject(signalSpy, testCase, {target: group, signalName: "clicked"}) verify(clickedSpy.valid) - var button1 = createTemporaryObject(button, testCase) - var button2 = createTemporaryObject(button, testCase) + let button1 = createTemporaryObject(button, testCase) + let button2 = createTemporaryObject(button, testCase) group.addButton(button1) group.addButton(button2) @@ -252,7 +254,7 @@ TestCase { } function test_controls(data) { - var container = createTemporaryObject(data.component, testCase) + let container = createTemporaryObject(data.component, testCase) verify(container) verify(!container.group.checkedButton) @@ -277,13 +279,13 @@ TestCase { } function test_buttonDestroyed() { - var group = createTemporaryObject(buttonGroup, testCase) + let group = createTemporaryObject(buttonGroup, testCase) verify(group) - var buttonsSpy = createTemporaryObject(signalSpy, testCase, {target: group, signalName: "buttonsChanged"}) + let buttonsSpy = createTemporaryObject(signalSpy, testCase, {target: group, signalName: "buttonsChanged"}) verify(buttonsSpy.valid) - var button1 = createTemporaryObject(button, testCase, {objectName: "button1", checked: true}) + let button1 = createTemporaryObject(button, testCase, {objectName: "button1", checked: true}) group.addButton(button1) compare(group.buttons.length, 1) @@ -316,7 +318,7 @@ TestCase { } function test_repeater() { - var container = createTemporaryObject(repeater, testCase) + let container = createTemporaryObject(repeater, testCase) verify(container) verify(container.group.checkedButton) @@ -324,25 +326,25 @@ TestCase { } function test_nonExclusive() { - var group = createTemporaryObject(nonExclusiveGroup, testCase) + let group = createTemporaryObject(nonExclusiveGroup, testCase) verify(group) compare(group.checkState, Qt.Unchecked) - var button1 = createTemporaryObject(button, testCase, {checked: true}) + let button1 = createTemporaryObject(button, testCase, {checked: true}) group.addButton(button1) compare(button1.checked, true) compare(group.checkedButton, null) compare(group.checkState, Qt.Checked) - var button2 = createTemporaryObject(button, testCase, {checked: true}) + let button2 = createTemporaryObject(button, testCase, {checked: true}) group.addButton(button2) compare(button1.checked, true) compare(button2.checked, true) compare(group.checkedButton, null) compare(group.checkState, Qt.Checked) - var button3 = createTemporaryObject(button, testCase, {checked: false}) + let button3 = createTemporaryObject(button, testCase, {checked: false}) group.addButton(button3) compare(button1.checked, true) compare(button2.checked, true) @@ -401,7 +403,7 @@ TestCase { model: ListModel { id: listModel Component.onCompleted: { - for (var i = 0; i < 10; ++i) + for (let i = 0; i < 10; ++i) append({text: i}) } } @@ -410,11 +412,63 @@ TestCase { } function test_checkedButtonDestroyed() { - var column = createTemporaryObject(checkedButtonColumn, testCase) + let column = createTemporaryObject(checkedButtonColumn, testCase) verify(column) waitForRendering(column) mouseClick(column.children[0]) wait(0) // don't crash (QTBUG-62946, QTBUG-63470) } + + Component { + id: buttonGroupComp + + Item { + + property ButtonGroup buttonGroup: ButtonGroup { } + property int buttonGroupCount: buttonGroup.buttons.length + property int buttonGrpSigCnt: 0 + + function clearButtonGroup() { + buttonGroup.buttons = [] + } + function assignButtonGroup() { + radioButton1.ButtonGroup.group = buttonGroup + } + + Column { + RadioButton { + id: radioButton1 + visible: false + ButtonGroup.group: buttonGroup + ButtonGroup.onGroupChanged: { (ButtonGroup.group === null) ? --buttonGrpSigCnt : ++buttonGrpSigCnt } + } + RadioButton { + id: radioButton2 + visible: false + ButtonGroup.group: buttonGroup + ButtonGroup.onGroupChanged: { (ButtonGroup.group === null) ? --buttonGrpSigCnt : ++buttonGrpSigCnt } + } + } + } + } + + function test_resetButtonGroup() { + let container = createTemporaryObject(buttonGroupComp, testCase) + verify(container) + + // Check for initial buttons assigned to button group + compare(container.buttonGroupCount, 2) + compare(container.buttonGrpSigCnt, 2) + // Clear buttons in the button group + container.clearButtonGroup() + // Check for buttons in the group and group changed event for buttons + compare(container.buttonGroupCount, 0) + compare(container.buttonGrpSigCnt, 0) + // Assign same group to the button + container.assignButtonGroup() + // Check for group change event from the button + compare(container.buttonGroupCount, 1) + compare(container.buttonGrpSigCnt, 1) + } } diff --git a/tests/auto/quickcontrols/controls/data/tst_calendarmodel.qml b/tests/auto/quickcontrols/controls/data/tst_calendarmodel.qml index 19070e074d..3cb35ab266 100644 --- a/tests/auto/quickcontrols/controls/data/tst_calendarmodel.qml +++ b/tests/auto/quickcontrols/controls/data/tst_calendarmodel.qml @@ -1,5 +1,5 @@ // Copyright (C) 2021 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only import QtQml import QtQuick @@ -29,32 +29,45 @@ TestCase { } } + function init() { + failOnWarning(/.?/) + } + function test_indices_data() { return [ + // "from" and "to" must currently be in the same year. { tag: "2013", from: "2013-01-01", to: "2013-12-31", count: 12 }, - { tag: "2016", from: "2016-01-01", to: "2016-03-31", count: 3 } + { tag: "2016", from: "2016-01-01", to: "2016-03-31", count: 3 }, + { tag: "2016-02-01 to 2016-12-31", from: "2016-02-01", to: "2016-12-31", count: 11 }, + { tag: "2014-11-30 to 2016-01-01", from: "2014-11-30", to: "2016-01-01", count: 15 } ] } function test_indices(data) { - var model = calendarModel.createObject(testCase, {from: data.from, to: data.to}) + let model = calendarModel.createObject(testCase, {from: data.from, to: data.to}) verify(model) compare(model.count, data.count) - var y = parseInt(data.tag) - for (var m = 0; m < 12; ++m) { - compare(model.yearAt(m), y) - compare(model.indexOf(y, m), m) - compare(model.indexOf(new Date(y, m, 1)), m) - compare(model.monthAt(m), m) + const from = new Date(data.from) + const to = new Date(data.to) + let index = 0 + for (let date = from; date <= to; date.setMonth(date.getMonth() + 1, 28), ++index) { + compare(model.yearAt(index), date.getFullYear(), + `yearAt(${index}) returned incorrect value`) + compare(model.indexOf(date.getFullYear(), date.getMonth()), index, + `indexOf(${date.getFullYear()}, ${date.getMonth()}) returned incorrect value`) + compare(model.indexOf(date), index, + `indexOf(${date}) returned incorrect value`) + compare(model.monthAt(index), date.getMonth(), + `monthAt(${index}) returned incorrect value`) } model.destroy() } function test_invalid() { - var model = calendarModel.createObject(testCase) + let model = calendarModel.createObject(testCase) verify(model) compare(model.indexOf(-1, -1), -1) @@ -64,11 +77,11 @@ TestCase { } function test_instantiator() { - var inst = instantiator.createObject(testCase) + let inst = instantiator.createObject(testCase) verify(inst) compare(inst.count, 12) - for (var m = 0; m < inst.count; ++m) { + for (let m = 0; m < inst.count; ++m) { compare(inst.objectAt(m).month, m) compare(inst.objectAt(m).year, 2016) } diff --git a/tests/auto/quickcontrols/controls/data/tst_checkbox.qml b/tests/auto/quickcontrols/controls/data/tst_checkbox.qml index 5991ae9008..6c3b859e40 100644 --- a/tests/auto/quickcontrols/controls/data/tst_checkbox.qml +++ b/tests/auto/quickcontrols/controls/data/tst_checkbox.qml @@ -1,5 +1,5 @@ // Copyright (C) 2017 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only import QtQuick import QtTest @@ -25,9 +25,11 @@ TestCase { } } - function test_defaults() { + function init() { failOnWarning(/.?/) + } + function test_defaults() { let control = createTemporaryObject(checkBox, testCase) verify(control) compare(control.tristate, false) @@ -35,7 +37,7 @@ TestCase { } function test_text() { - var control = createTemporaryObject(checkBox, testCase) + let control = createTemporaryObject(checkBox, testCase) verify(control) compare(control.text, "") @@ -46,10 +48,10 @@ TestCase { } function test_checked() { - var control = createTemporaryObject(checkBox, testCase) + let control = createTemporaryObject(checkBox, testCase) verify(control) - var sequenceSpy = signalSequenceSpy.createObject(control, {target: control}) + let sequenceSpy = signalSequenceSpy.createObject(control, {target: control}) sequenceSpy.expectedSequence = [] compare(control.checked, false) @@ -72,10 +74,10 @@ TestCase { } function test_checkState() { - var control = createTemporaryObject(checkBox, testCase) + let control = createTemporaryObject(checkBox, testCase) verify(control) - var sequenceSpy = signalSequenceSpy.createObject(control, {target: control}) + let sequenceSpy = signalSequenceSpy.createObject(control, {target: control}) sequenceSpy.expectedSequence = [] compare(control.checked, false) @@ -98,10 +100,10 @@ TestCase { } function test_mouse() { - var control = createTemporaryObject(checkBox, testCase) + let control = createTemporaryObject(checkBox, testCase) verify(control) - var sequenceSpy = signalSequenceSpy.createObject(control, {target: control}) + let sequenceSpy = signalSequenceSpy.createObject(control, {target: control}) // check sequenceSpy.expectedSequence = [["pressedChanged", { "pressed": true, "checked": false, "checkState": Qt.Unchecked }], @@ -169,12 +171,12 @@ TestCase { } function test_touch() { - var control = createTemporaryObject(checkBox, testCase) + let control = createTemporaryObject(checkBox, testCase) verify(control) - var touch = touchEvent(control) + let touch = touchEvent(control) - var sequenceSpy = signalSequenceSpy.createObject(control, {target: control}) + let sequenceSpy = signalSequenceSpy.createObject(control, {target: control}) // check sequenceSpy.expectedSequence = [["pressedChanged", { "pressed": true, "checked": false, "checkState": Qt.Unchecked }], @@ -235,10 +237,10 @@ TestCase { } function test_keys() { - var control = createTemporaryObject(checkBox, testCase) + let control = createTemporaryObject(checkBox, testCase) verify(control) - var sequenceSpy = signalSequenceSpy.createObject(control, {target: control}) + let sequenceSpy = signalSequenceSpy.createObject(control, {target: control}) sequenceSpy.expectedSequence = [] control.forceActiveFocus() @@ -277,8 +279,8 @@ TestCase { sequenceSpy.expectedSequence = [] // Not testing Key_Enter and Key_Return because QGnomeTheme uses them for // pressing buttons and the CI uses the QGnomeTheme platform theme. - var keys = [Qt.Key_Escape, Qt.Key_Tab] - for (var i = 0; i < keys.length; ++i) { + let keys = [Qt.Key_Escape, Qt.Key_Tab] + for (let i = 0; i < keys.length; ++i) { sequenceSpy.reset() keyClick(keys[i]) compare(control.checked, false) @@ -295,7 +297,7 @@ TestCase { } function test_checked_binding() { - var container = createTemporaryObject(checkedBoundBoxes, testCase) + let container = createTemporaryObject(checkedBoundBoxes, testCase) verify(container) compare(container.cb1.checked, false) @@ -325,7 +327,7 @@ TestCase { } function test_checkState_binding() { - var container = createTemporaryObject(checkStateBoundBoxes, testCase) + let container = createTemporaryObject(checkStateBoundBoxes, testCase) verify(container) compare(container.cb1.checked, false) @@ -361,9 +363,9 @@ TestCase { } function test_tristate() { - var control = createTemporaryObject(checkBox, testCase, {tristate: true}) + let control = createTemporaryObject(checkBox, testCase, {tristate: true}) - var sequenceSpy = signalSequenceSpy.createObject(control, {target: control}) + let sequenceSpy = signalSequenceSpy.createObject(control, {target: control}) sequenceSpy.expectedSequence = [] control.forceActiveFocus() @@ -457,7 +459,7 @@ TestCase { } function test_baseline() { - var control = createTemporaryObject(checkBox, testCase) + let control = createTemporaryObject(checkBox, testCase) verify(control) compare(control.baselineOffset, control.contentItem.y + control.contentItem.baselineOffset) } @@ -484,7 +486,7 @@ TestCase { } function test_nextCheckState(data) { - var control = createTemporaryObject(nextCheckStateBox, testCase) + let control = createTemporaryObject(nextCheckStateBox, testCase) verify(control) // mouse @@ -496,7 +498,7 @@ TestCase { // touch control.checkState = data.checkState compare(control.checkState, data.checkState) - var touch = touchEvent(control) + let touch = touchEvent(control) touch.press(0, control).commit().release(0, control).commit() compare(control.checkState, data.expectedState) diff --git a/tests/auto/quickcontrols/controls/data/tst_checkdelegate.qml b/tests/auto/quickcontrols/controls/data/tst_checkdelegate.qml index d3e0910e83..acb6ebc653 100644 --- a/tests/auto/quickcontrols/controls/data/tst_checkdelegate.qml +++ b/tests/auto/quickcontrols/controls/data/tst_checkdelegate.qml @@ -1,5 +1,5 @@ // Copyright (C) 2017 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only import QtQuick import QtTest @@ -20,16 +20,18 @@ TestCase { // TODO: data-fy tst_checkbox (rename to tst_check?) so we don't duplicate its tests here? - function test_defaults() { + function init() { failOnWarning(/.?/) + } - var control = createTemporaryObject(checkDelegate, testCase); + function test_defaults() { + let control = createTemporaryObject(checkDelegate, testCase); verify(control); verify(!control.checked); } function test_checked() { - var control = createTemporaryObject(checkDelegate, testCase); + let control = createTemporaryObject(checkDelegate, testCase); verify(control); mouseClick(control); @@ -40,17 +42,17 @@ TestCase { } function test_baseline() { - var control = createTemporaryObject(checkDelegate, testCase); + let control = createTemporaryObject(checkDelegate, testCase); verify(control); compare(control.baselineOffset, control.contentItem.y + control.contentItem.baselineOffset); } function test_spacing() { - var control = createTemporaryObject(checkDelegate, testCase, { text: "Some long, long, long text" }) + let control = createTemporaryObject(checkDelegate, testCase, { text: "Some long, long, long text" }) verify(control) verify(control.contentItem.implicitWidth + control.leftPadding + control.rightPadding > control.background.implicitWidth) - var textLabel = findChild(control.contentItem, "label") + let textLabel = findChild(control.contentItem, "label") verify(textLabel) // The implicitWidth of the IconLabel that all buttons use as their contentItem should be @@ -77,7 +79,7 @@ TestCase { } function test_display(data) { - var control = createTemporaryObject(checkDelegate, testCase, { + let control = createTemporaryObject(checkDelegate, testCase, { text: "CheckDelegate", display: data.display, width: 400, @@ -87,11 +89,11 @@ TestCase { verify(control) compare(control.icon.source, "qrc:/qt-project.org/imports/QtQuick/Controls/Basic/images/check.png") - var iconImage = findChild(control.contentItem, "image") - var textLabel = findChild(control.contentItem, "label") + let iconImage = findChild(control.contentItem, "image") + let textLabel = findChild(control.contentItem, "label") - var availableWidth = control.availableWidth - control.indicator.width - control.spacing - var indicatorOffset = control.mirrored ? control.indicator.width + control.spacing : 0 + let availableWidth = control.availableWidth - control.indicator.width - control.spacing + let indicatorOffset = control.mirrored ? control.indicator.width + control.spacing : 0 switch (control.display) { case CheckDelegate.IconOnly: @@ -148,7 +150,7 @@ TestCase { } function test_nextCheckState(data) { - var control = createTemporaryObject(nextCheckStateDelegate, testCase) + let control = createTemporaryObject(nextCheckStateDelegate, testCase) verify(control) // mouse @@ -160,7 +162,7 @@ TestCase { // touch control.checkState = data.checkState compare(control.checkState, data.checkState) - var touch = touchEvent(control) + let touch = touchEvent(control) touch.press(0, control).commit().release(0, control).commit() compare(control.checkState, data.expectedState) diff --git a/tests/auto/quickcontrols/controls/data/tst_combobox.qml b/tests/auto/quickcontrols/controls/data/tst_combobox.qml index 5bb9d61815..3027d70440 100644 --- a/tests/auto/quickcontrols/controls/data/tst_combobox.qml +++ b/tests/auto/quickcontrols/controls/data/tst_combobox.qml @@ -1,10 +1,11 @@ // Copyright (C) 2017 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only import QtQuick import QtQuick.Window import QtTest import QtQuick.Controls +import Qt.test.controls import QtQuick.NativeStyle as NativeStyle TestCase { @@ -74,16 +75,7 @@ TestCase { objectName: "ShaderFX" width: rect.width height: rect.height - fragmentShader: " - uniform lowp sampler2D source; // this item - uniform lowp float qt_Opacity; // inherited opacity of this item - varying highp vec2 qt_TexCoord0; - void main() { - lowp vec4 p = texture2D(source, qt_TexCoord0); - lowp float g = dot(p.xyz, vec3(0.344, 0.5, 0.156)); - gl_FragColor = vec4(g, g, g, p.a) * qt_Opacity; - }" - + fragmentShader: "combobox/shader.frag.qsb" } } } @@ -878,22 +870,27 @@ TestCase { // Account for when a transition of a scale from 0.9-1.0 that it is placed above right away and not below // first just because there is room at the 0.9 scale if (control.popup.enter !== null) { - // hide - mouseClick(control) - compare(control.pressed, false) - tryCompare(control.popup, "visible", false) - control.y = control.Window.height - (control.popup.contentItem.height * 0.99) - var popupYSpy = createTemporaryObject(signalSpy, testCase, {target: control.popup, signalName: "yChanged"}) - verify(popupYSpy.valid) - mousePress(control) - compare(control.pressed, true) - compare(control.popup.visible, false) - mouseRelease(control) - compare(control.pressed, false) - compare(control.popup.visible, true) - tryCompare(control.popup.enter, "running", false) - verify(control.popup.contentItem.y < control.y) - verify(popupYSpy.count === 1) + // test only if there is a scale animation + let scaleAnimation = control.popup.enter.animations.some((animation) => { + return (animation instanceof PropertyAnimation && animation.property === "scale") + }); + if (scaleAnimation) { + // hide + mouseClick(control) + compare(control.pressed, false) + tryCompare(control.popup, "visible", false) + control.y = control.Window.height - (control.popup.contentItem.height * 0.99) + var popupYSpy = createTemporaryObject(signalSpy, testCase, {target: control.popup, signalName: "yChanged"}) + verify(popupYSpy.valid) + mousePress(control) + compare(control.pressed, true) + compare(control.popup.visible, false) + mouseRelease(control) + compare(control.pressed, false) + tryCompare(control.popup, "opened", true) + verify(control.popup.contentItem.y < control.y) + verify(popupYSpy.count === 1) + } } var leftLayoutMargin = control.background.layoutMargins === undefined ? 0 : control.popup.layoutMargins.left @@ -949,7 +946,8 @@ TestCase { // Check on the second opening that it has the same y position as before if (i !== 0) { // y should not have changed again - verify(popupYSpy.count === 0) + if (StyleInfo.styleName !== "FluentWinUI3") // the popup y in FluentWinUI3 depends on the implicitHeight + verify(popupYSpy.count === 0) verify(y === control.innerCombo.popup.y) } else { // In some cases on the initial show, y changes more than once @@ -1024,6 +1022,7 @@ TestCase { compare(activatedSpy.count, 0) compare(highlightedSpy.count, 0) compare(control.popup.visible, true) + tryCompare(control.popup, "opened", true) // press - move - release inside - activated - closed touch.press(0, content).commit() @@ -1710,7 +1709,7 @@ TestCase { ComboBox { editable: true property bool gotit: false - Keys.onPressed: { + Keys.onPressed: function (event) { if (!gotit && event.key === Qt.Key_B) { gotit = true event.accepted = true @@ -1787,7 +1786,7 @@ TestCase { // Ensure that it's open so that the popup's implicitHeight changes when we increase the model count. control.popup.open() - tryCompare(control.popup, "visible", true) + tryCompare(control.popup, "opened", true) // Add lots of items to the model. The popup should take up the entire height of the window. control.model = 100 @@ -1799,6 +1798,8 @@ TestCase { control.model = 0 control.popup.open() tryCompare(control.popup, "visible", true) + if (control.popup.enter !== null) + tryCompare(control.popup.enter, "running", false) compare(control.popup.height, control.popup.topPadding + control.popup.bottomPadding) } @@ -2004,11 +2005,16 @@ TestCase { compare(currentIndexSpy.count, 1) } + readonly property font testFont: ({ + family: "Arial", + pixelSize: 12 + }) + Component { - id: appFontTextFieldComponent + id: fixedFontTextFieldComponent TextField { objectName: "appFontTextField" - font: Qt.application.font + font: testCase.testFont // We don't want the background's implicit width to interfere with our tests, // which are about implicit width of the contentItem of ComboBox, which is by default TextField. background: null @@ -2016,14 +2022,14 @@ TestCase { } Component { - id: appFontContentItemComboBoxComponent + id: fixedFontContentItemComboBoxComponent ComboBox { // Override the contentItem so that the font doesn't vary between styles. contentItem: TextField { objectName: "appFontContentItemTextField" // We do this just to be extra sure that the font never comes from the control, - // as we want it to match that of the TextField in the appFontTextFieldComponent. - font: Qt.application.font + // as we want it to match that of the TextField in the fixedFontTextFieldComponent. + font: testCase.testFont background: null } } @@ -2077,14 +2083,14 @@ TestCase { function test_implicitContentWidthPolicy_ContentItemImplicitWidth() { // Set ContentItemImplicitWidth and ensure that implicitContentWidth is as wide as the current item // by comparing it against the implicitWidth of an identical TextField - let control = createTemporaryObject(appFontContentItemComboBoxComponent, testCase, { + let control = createTemporaryObject(fixedFontContentItemComboBoxComponent, testCase, { model: ["Short", "Kinda long"], implicitContentWidthPolicy: ComboBox.ContentItemImplicitWidth }) verify(control) compare(control.implicitContentWidthPolicy, ComboBox.ContentItemImplicitWidth) - let textField = createTemporaryObject(appFontTextFieldComponent, testCase) + let textField = createTemporaryObject(fixedFontTextFieldComponent, testCase) verify(textField) // Don't set any text on textField because we're not accounting for the widest // text here, so we want to compare it against an empty TextField. @@ -2103,14 +2109,14 @@ TestCase { } function test_implicitContentWidthPolicy_WidestText(data) { - let control = createTemporaryObject(appFontContentItemComboBoxComponent, testCase, { + let control = createTemporaryObject(fixedFontContentItemComboBoxComponent, testCase, { model: data.model, implicitContentWidthPolicy: ComboBox.WidestText }) verify(control) compare(control.implicitContentWidthPolicy, ComboBox.WidestText) - let textField = createTemporaryObject(appFontTextFieldComponent, testCase) + let textField = createTemporaryObject(fixedFontTextFieldComponent, testCase) verify(textField) textField.text = "Kinda long" // Note that we don't need to change the current index here, as the implicitContentWidth @@ -2137,7 +2143,7 @@ TestCase { // Changes in font should result in the implicitContentWidth being updated. textField.font.pixelSize *= 2 // We have to change the contentItem's font size manually since we break the - // style's binding to the control's font when we set Qt.application.font to it. + // style's binding to the control's font when we set the fixed font on it. control.contentItem.font.pixelSize *= 2 control.font.pixelSize *= 2 compare(Math.ceil(control.implicitContentWidth), Math.ceil(textField.implicitWidth)) @@ -2148,14 +2154,14 @@ TestCase { } function test_implicitContentWidthPolicy_WidestTextWhenCompleted(data) { - let control = createTemporaryObject(appFontContentItemComboBoxComponent, testCase, { + let control = createTemporaryObject(fixedFontContentItemComboBoxComponent, testCase, { model: data.model, implicitContentWidthPolicy: ComboBox.WidestTextWhenCompleted }) verify(control) compare(control.implicitContentWidthPolicy, ComboBox.WidestTextWhenCompleted) - let textField = createTemporaryObject(appFontTextFieldComponent, testCase) + let textField = createTemporaryObject(fixedFontTextFieldComponent, testCase) verify(textField) textField.text = "Kinda long" compare(Math.ceil(control.implicitContentWidth), Math.ceil(textField.implicitWidth)) @@ -2277,6 +2283,35 @@ TestCase { compare(control.currentIndex, 1) } + // QTBUG-109721 - verify that an eaten press event for the space key + // doesn't open the popup when the key is released. + Component { + id: comboboxEatsSpace + ComboBox { + id: nonEditableComboBox + editable: false + model: ["NonEditable", "Delta", "Echo", "Foxtrot"] + Keys.onSpacePressed: (event) => event.accept + } + } + + function test_spacePressEaten() { + let control = createTemporaryObject(comboboxEatsSpace, testCase) + verify(control) + control.forceActiveFocus() + + var visibleChangedSpy = signalSpy.createObject(control, {target: control.popup, signalName: "visibleChanged"}) + verify(visibleChangedSpy.valid) + + // press doesn't open + keyPress(Qt.Key_Space) + verify(!control.pressed) + compare(visibleChangedSpy.count, 0) + // neither does release + keyRelease(Qt.Key_Space) + compare(visibleChangedSpy.count, 0) + } + Component { id: listOfGadgets QtObject { @@ -2295,4 +2330,25 @@ TestCase { control.currentIndex = 1; compare(control.displayText, "7"); } + + function test_contextObject() { + // We use the default delegate with required properties and pass + // an array of objects as model. This should work despite + // ComboBox setting itself as model object for the delegate. + + let control = createTemporaryObject( + comboBox, testCase, {model: fruitarray, textRole: "color"}); + verify(control); + compare(control.popup.contentItem.itemAtIndex(0).text, "red"); + + // Now we pass an AbstractItemModel with 2 roles. Since we use required properties + // the model object should still have the anonymous property, and it should be a + // QQmlDMAbstractItemModelData. + + control = createTemporaryObject(comboBox, testCase, { model: fruitmodel }); + verify(control); + for (var i = 0; i < 3; ++i) + ignoreWarning(/ComboBox\.qml\:[0-9]+\:[0-9]+\: Unable to assign QQmlDMAbstractItemModelData to QString/); + compare(control.popup.contentItem.itemAtIndex(0).text, ""); + } } diff --git a/tests/auto/quickcontrols/controls/data/tst_container.qml b/tests/auto/quickcontrols/controls/data/tst_container.qml index 9988625744..35c9f93b05 100644 --- a/tests/auto/quickcontrols/controls/data/tst_container.qml +++ b/tests/auto/quickcontrols/controls/data/tst_container.qml @@ -1,5 +1,5 @@ // Copyright (C) 2017 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only import QtQuick import QtTest @@ -24,16 +24,18 @@ TestCase { Rectangle { } } - function test_defaults() { + function init() { failOnWarning(/.?/) + } + function test_defaults() { let control = createTemporaryObject(container, testCase) verify(control) compare(control.count, 0) } function test_implicitSize() { - var control = createTemporaryObject(container, testCase) + let control = createTemporaryObject(container, testCase) verify(control) compare(control.implicitWidth, 0) @@ -53,16 +55,16 @@ TestCase { } function test_currentIndex() { - var control1 = createTemporaryObject(container, testCase) + let control1 = createTemporaryObject(container, testCase) verify(control1) - var control2 = createTemporaryObject(container, testCase) + let control2 = createTemporaryObject(container, testCase) verify(control2) compare(control1.currentIndex, -1) compare(control2.currentIndex, -1) - for (var i = 0; i < 3; ++i) { + for (let i = 0; i < 3; ++i) { control1.addItem(rectangle.createObject(control1)) control2.addItem(rectangle.createObject(control2)) } @@ -130,7 +132,7 @@ TestCase { // don't crash (QTBUG-61310) function test_repeater(data) { - var control = createTemporaryObject(data.component, testCase) + let control = createTemporaryObject(data.component, testCase) verify(control) compare(control.itemAt(0).objectName, "0") @@ -140,12 +142,12 @@ TestCase { } function test_removeTakeItem() { - var control = createTemporaryObject(container, testCase) + let control = createTemporaryObject(container, testCase) verify(control) - var item1 = rectangle.createObject(control) - var item2 = rectangle.createObject(control) - var item3 = rectangle.createObject(control) + let item1 = rectangle.createObject(control) + let item2 = rectangle.createObject(control) + let item3 = rectangle.createObject(control) item1.Component.onDestruction.connect(function() { item1 = null }) item2.Component.onDestruction.connect(function() { item2 = null }) @@ -210,9 +212,9 @@ TestCase { } function test_contentItemDeletionOrder() { - var control1 = createTemporaryObject(contentItemDeletionOrder1, testCase) + let control1 = createTemporaryObject(contentItemDeletionOrder1, testCase) verify(control1) - var control2 = createTemporaryObject(contentItemDeletionOrder2, testCase) + let control2 = createTemporaryObject(contentItemDeletionOrder2, testCase) verify(control2) } @@ -251,9 +253,9 @@ TestCase { } function test_backgroundDeletionOrder() { - var control1 = createTemporaryObject(backgroundDeletionOrder1, testCase) + let control1 = createTemporaryObject(backgroundDeletionOrder1, testCase) verify(control1) - var control2 = createTemporaryObject(backgroundDeletionOrder2, testCase) + let control2 = createTemporaryObject(backgroundDeletionOrder2, testCase) verify(control2) } } diff --git a/tests/auto/quickcontrols/controls/data/tst_control.qml b/tests/auto/quickcontrols/controls/data/tst_control.qml index 0747943421..a3e65f2b0f 100644 --- a/tests/auto/quickcontrols/controls/data/tst_control.qml +++ b/tests/auto/quickcontrols/controls/data/tst_control.qml @@ -1,5 +1,5 @@ // Copyright (C) 2017 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only import QtQuick import QtTest @@ -34,9 +34,11 @@ TestCase { SignalSpy { } } - function test_defaults() { + function init() { failOnWarning(/.?/) + } + function test_defaults() { let control = createTemporaryObject(component, testCase) verify(control) compare(control.background, null) @@ -44,37 +46,37 @@ TestCase { } function test_padding() { - var control = createTemporaryObject(component, testCase) + let control = createTemporaryObject(component, testCase) verify(control) - var paddingSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "paddingChanged"}) + let paddingSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "paddingChanged"}) verify(paddingSpy.valid) - var topPaddingSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "topPaddingChanged"}) + let topPaddingSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "topPaddingChanged"}) verify(topPaddingSpy.valid) - var leftPaddingSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "leftPaddingChanged"}) + let leftPaddingSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "leftPaddingChanged"}) verify(leftPaddingSpy.valid) - var rightPaddingSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "rightPaddingChanged"}) + let rightPaddingSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "rightPaddingChanged"}) verify(rightPaddingSpy.valid) - var bottomPaddingSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "bottomPaddingChanged"}) + let bottomPaddingSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "bottomPaddingChanged"}) verify(bottomPaddingSpy.valid) - var horizontalPaddingSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "horizontalPaddingChanged"}) + let horizontalPaddingSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "horizontalPaddingChanged"}) verify(horizontalPaddingSpy.valid) - var verticalPaddingSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "verticalPaddingChanged"}) + let verticalPaddingSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "verticalPaddingChanged"}) verify(verticalPaddingSpy.valid) - var paddingChanges = 0 - var topPaddingChanges = 0 - var leftPaddingChanges = 0 - var rightPaddingChanges = 0 - var bottomPaddingChanges = 0 - var horizontalPaddingChanges = 0 - var verticalPaddingChanges = 0 + let paddingChanges = 0 + let topPaddingChanges = 0 + let leftPaddingChanges = 0 + let rightPaddingChanges = 0 + let bottomPaddingChanges = 0 + let horizontalPaddingChanges = 0 + let verticalPaddingChanges = 0 compare(control.padding, 0) compare(control.topPadding, 0) @@ -315,17 +317,17 @@ TestCase { } function test_availableSize() { - var control = createTemporaryObject(component, testCase) + let control = createTemporaryObject(component, testCase) verify(control) - var availableWidthSpy = signalSpy.createObject(control, {target: control, signalName: "availableWidthChanged"}) + let availableWidthSpy = signalSpy.createObject(control, {target: control, signalName: "availableWidthChanged"}) verify(availableWidthSpy.valid) - var availableHeightSpy = signalSpy.createObject(control, {target: control, signalName: "availableHeightChanged"}) + let availableHeightSpy = signalSpy.createObject(control, {target: control, signalName: "availableHeightChanged"}) verify(availableHeightSpy.valid) - var availableWidthChanges = 0 - var availableHeightChanges = 0 + let availableWidthChanges = 0 + let availableHeightChanges = 0 control.width = 100 compare(control.availableWidth, 100) @@ -385,10 +387,10 @@ TestCase { } function test_mirrored() { - var control = createTemporaryObject(component, testCase) + let control = createTemporaryObject(component, testCase) verify(control) - var mirroredSpy = signalSpy.createObject(control, {target: control, signalName: "mirroredChanged"}) + let mirroredSpy = signalSpy.createObject(control, {target: control, signalName: "mirroredChanged"}) verify(mirroredSpy.valid) control.locale = Qt.locale("en_US") @@ -414,7 +416,7 @@ TestCase { } function test_background() { - var control = createTemporaryObject(component, testCase) + let control = createTemporaryObject(component, testCase) verify(control) control.background = component.createObject(control) @@ -465,6 +467,36 @@ TestCase { } Component { + id: backgroundTest2 + Button { + id: btn + width: 100 + height: 100 + topInset: 0 + objectName: "" + + background: Rectangle { + id: bg + implicitHeight: 80 + border.color: "red" + y: btn.objectName === "aaa" ? 20 : 0 + } + } + } + + // QTBUG-120033: Make sure that the binding for y on the tab button's background doesn't get removed + function test_background2() { + let button = createTemporaryObject(backgroundTest2, testCase) + verify(button) + + verify(button.background.y === 0) + button.objectName = "aaa" + verify(button.background.y === 20) + button.objectName = "" + verify(button.background.y === 0) + } + + Component { id: component2 T.Control { id: item2 @@ -502,7 +534,7 @@ TestCase { } function test_font() { - var control2 = createTemporaryObject(component2, testCase) + let control2 = createTemporaryObject(component2, testCase) verify(control2) verify(control2.item2_2) verify(control2.item2_3) @@ -645,7 +677,7 @@ TestCase { } function test_font_2() { - var control3 = createTemporaryObject(component3, testCase) + let control3 = createTemporaryObject(component3, testCase) verify(control3) verify(control3.item3_2) verify(control3.item3_3) @@ -760,14 +792,14 @@ TestCase { } function test_font_3() { - var control4 = createTemporaryObject(component4, testCase) + let control4 = createTemporaryObject(component4, testCase) verify(control4) verify(control4.item4_2) verify(control4.item4_3) verify(control4.item4_4) - var family = control4.font.family - var ps = control4.font.pixelSize + let family = control4.font.family + let ps = control4.font.pixelSize compare(control4.item4_2.font.family, control4.font.family) compare(control4.item4_3.font.family, control4.font.family) @@ -797,19 +829,19 @@ TestCase { } function test_font_explicit_attributes(data) { - var control = createTemporaryObject(component, testCase) + let control = createTemporaryObject(component, testCase) verify(control) - var child = component.createObject(control) + let child = component.createObject(control) verify(child) - var controlSpy = signalSpy.createObject(control, {target: control, signalName: "fontChanged"}) + let controlSpy = signalSpy.createObject(control, {target: control, signalName: "fontChanged"}) verify(controlSpy.valid) - var childSpy = signalSpy.createObject(child, {target: child, signalName: "fontChanged"}) + let childSpy = signalSpy.createObject(child, {target: child, signalName: "fontChanged"}) verify(childSpy.valid) - var defaultValue = control.font[data.tag] + let defaultValue = control.font[data.tag] child.font[data.tag] = defaultValue compare(child.font[data.tag], defaultValue) @@ -825,7 +857,7 @@ TestCase { } function test_locale() { - var control = createTemporaryObject(component, testCase) + let control = createTemporaryObject(component, testCase) verify(control) control.locale = Qt.locale("en_US") @@ -896,12 +928,12 @@ TestCase { } function test_locale_2() { - var control = createTemporaryObject(component5, testCase) + let control = createTemporaryObject(component5, testCase) verify(control) verify(control.item2_2) verify(control.item2_3) - var defaultLocale = Qt.locale() + let defaultLocale = Qt.locale() compare(control.locale.name, defaultLocale.name) compare(control.item2_2.locale.name, defaultLocale.name) @@ -989,14 +1021,14 @@ TestCase { } function test_locale_3() { - var control = createTemporaryObject(component6, testCase) + let control = createTemporaryObject(component6, testCase) verify(control) verify(control.item6_2) verify(control.item6_3) verify(control.item6_4) verify(control.item6_5) - var defaultLocale = Qt.locale() + let defaultLocale = Qt.locale() compare(control.locale.name, defaultLocale.name) compare(control.item6_5.locale.name, defaultLocale.name) @@ -1028,7 +1060,7 @@ TestCase { } function test_hover(data) { - var control = createTemporaryObject(data.target, testCase, {width: 100, height: 100}) + let control = createTemporaryObject(data.target, testCase, {width: 100, height: 100}) verify(control) compare(control.hovered, false) @@ -1065,17 +1097,17 @@ TestCase { } function test_hoverEnabled() { - var control = createTemporaryObject(component, testCase) + let control = createTemporaryObject(component, testCase) compare(control.hoverEnabled, Qt.styleHints.useHoverEffects) - var child = component.createObject(control) - var grandChild = component.createObject(child) + let child = component.createObject(control) + let grandChild = component.createObject(child) - var childExplicitHoverEnabled = component.createObject(control, {hoverEnabled: true}) - var grandChildExplicitHoverDisabled = component.createObject(childExplicitHoverEnabled, {hoverEnabled: false}) + let childExplicitHoverEnabled = component.createObject(control, {hoverEnabled: true}) + let grandChildExplicitHoverDisabled = component.createObject(childExplicitHoverEnabled, {hoverEnabled: false}) - var childExplicitHoverDisabled = component.createObject(control, {hoverEnabled: false}) - var grandChildExplicitHoverEnabled = component.createObject(childExplicitHoverDisabled, {hoverEnabled: true}) + let childExplicitHoverDisabled = component.createObject(control, {hoverEnabled: false}) + let grandChildExplicitHoverEnabled = component.createObject(childExplicitHoverDisabled, {hoverEnabled: true}) control.hoverEnabled = false compare(control.hoverEnabled, false) @@ -1099,33 +1131,33 @@ TestCase { } function test_implicitSize() { - var control = createTemporaryObject(component, testCase) + let control = createTemporaryObject(component, testCase) verify(control) - var implicitWidthSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "implicitWidthChanged"}) + let implicitWidthSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "implicitWidthChanged"}) verify(implicitWidthSpy.valid) - var implicitHeightSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "implicitHeightChanged"}) + let implicitHeightSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "implicitHeightChanged"}) verify(implicitHeightSpy.valid) - var implicitContentWidthSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "implicitContentWidthChanged"}) + let implicitContentWidthSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "implicitContentWidthChanged"}) verify(implicitContentWidthSpy.valid) - var implicitContentHeightSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "implicitContentHeightChanged"}) + let implicitContentHeightSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "implicitContentHeightChanged"}) verify(implicitContentHeightSpy.valid) - var implicitBackgroundWidthSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "implicitBackgroundWidthChanged"}) + let implicitBackgroundWidthSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "implicitBackgroundWidthChanged"}) verify(implicitBackgroundWidthSpy.valid) - var implicitBackgroundHeightSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "implicitBackgroundHeightChanged"}) + let implicitBackgroundHeightSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "implicitBackgroundHeightChanged"}) verify(implicitBackgroundHeightSpy.valid) - var implicitWidthChanges = 0 - var implicitHeightChanges = 0 - var implicitContentWidthChanges = 0 - var implicitContentHeightChanges = 0 - var implicitBackgroundWidthChanges = 0 - var implicitBackgroundHeightChanges = 0 + let implicitWidthChanges = 0 + let implicitHeightChanges = 0 + let implicitContentWidthChanges = 0 + let implicitContentHeightChanges = 0 + let implicitBackgroundWidthChanges = 0 + let implicitBackgroundHeightChanges = 0 compare(control.implicitWidth, 0) compare(control.implicitHeight, 0) @@ -1194,12 +1226,12 @@ TestCase { } function test_baseline() { - var control = createTemporaryObject(component, testCase) + let control = createTemporaryObject(component, testCase) verify(control) compare(control.baselineOffset, 0) - var baselineSpy = signalSpy.createObject(control, {target: control, signalName: "baselineOffsetChanged"}) + let baselineSpy = signalSpy.createObject(control, {target: control, signalName: "baselineOffsetChanged"}) verify(baselineSpy.valid) control.contentItem = rectangle.createObject(control, {baselineOffset: 12}) @@ -1232,25 +1264,25 @@ TestCase { } function test_inset() { - var control = createTemporaryObject(component, testCase, {background: rectangle.createObject(control)}) + let control = createTemporaryObject(component, testCase, {background: rectangle.createObject(null)}) verify(control) - var topInsetSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "topInsetChanged"}) + let topInsetSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "topInsetChanged"}) verify(topInsetSpy.valid) - var leftInsetSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "leftInsetChanged"}) + let leftInsetSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "leftInsetChanged"}) verify(leftInsetSpy.valid) - var rightInsetSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "rightInsetChanged"}) + let rightInsetSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "rightInsetChanged"}) verify(rightInsetSpy.valid) - var bottomInsetSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "bottomInsetChanged"}) + let bottomInsetSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "bottomInsetChanged"}) verify(bottomInsetSpy.valid) - var topInsetChanges = 0 - var leftInsetChanges = 0 - var rightInsetChanges = 0 - var bottomInsetChanges = 0 + let topInsetChanges = 0 + let leftInsetChanges = 0 + let rightInsetChanges = 0 + let bottomInsetChanges = 0 compare(control.topInset, 0) compare(control.leftInset, 0) @@ -1412,9 +1444,9 @@ TestCase { } function test_contentItemDeletionOrder() { - var control1 = createTemporaryObject(contentItemDeletionOrder1, testCase) + let control1 = createTemporaryObject(contentItemDeletionOrder1, testCase) verify(control1) - var control2 = createTemporaryObject(contentItemDeletionOrder2, testCase) + let control2 = createTemporaryObject(contentItemDeletionOrder2, testCase) verify(control2) } @@ -1453,9 +1485,9 @@ TestCase { } function test_backgroundDeletionOrder() { - var control1 = createTemporaryObject(backgroundDeletionOrder1, testCase) + let control1 = createTemporaryObject(backgroundDeletionOrder1, testCase) verify(control1) - var control2 = createTemporaryObject(backgroundDeletionOrder2, testCase) + let control2 = createTemporaryObject(backgroundDeletionOrder2, testCase) verify(control2) } } diff --git a/tests/auto/quickcontrols/controls/data/tst_dayofweekrow.qml b/tests/auto/quickcontrols/controls/data/tst_dayofweekrow.qml index 67403e240a..b93337e62d 100644 --- a/tests/auto/quickcontrols/controls/data/tst_dayofweekrow.qml +++ b/tests/auto/quickcontrols/controls/data/tst_dayofweekrow.qml @@ -1,5 +1,5 @@ // Copyright (C) 2021 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only import QtQuick import QtQuick.Controls @@ -18,15 +18,17 @@ TestCase { DayOfWeekRow { } } - function test_defaults() { + function init () { failOnWarning(/.?/) + } + function test_defaults() { let control = createTemporaryObject(component, testCase) verify(control) } function test_locale() { - var control = component.createObject(testCase) + let control = component.createObject(testCase) verify(control.contentItem.children[0]) @@ -43,7 +45,7 @@ TestCase { } function test_font() { - var control = component.createObject(testCase) + let control = component.createObject(testCase) verify(control.contentItem.children[0]) diff --git a/tests/auto/quickcontrols/controls/data/tst_delaybutton.qml b/tests/auto/quickcontrols/controls/data/tst_delaybutton.qml index e2abe389ca..708e6a8a22 100644 --- a/tests/auto/quickcontrols/controls/data/tst_delaybutton.qml +++ b/tests/auto/quickcontrols/controls/data/tst_delaybutton.qml @@ -1,5 +1,5 @@ // Copyright (C) 2017 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only import QtQuick import QtTest @@ -38,18 +38,20 @@ TestCase { SignalSpy { } } - function test_defaults() { + function init() { failOnWarning(/.?/) + } + function test_defaults() { let control = createTemporaryObject(defaultComponent, testCase) verify(control) } function test_mouse() { - var control = createTemporaryObject(delayButton, testCase) + let control = createTemporaryObject(delayButton, testCase) verify(control) - var sequenceSpy = signalSequenceSpy.createObject(control, {target: control}) + let sequenceSpy = signalSequenceSpy.createObject(control, {target: control}) // click sequenceSpy.expectedSequence = [["pressedChanged", { "pressed": true }], @@ -145,12 +147,12 @@ TestCase { } function test_touch() { - var control = createTemporaryObject(delayButton, testCase) + let control = createTemporaryObject(delayButton, testCase) verify(control) - var touch = touchEvent(control) + let touch = touchEvent(control) - var sequenceSpy = signalSequenceSpy.createObject(control, {target: control}) + let sequenceSpy = signalSequenceSpy.createObject(control, {target: control}) // click sequenceSpy.expectedSequence = [["pressedChanged", { "pressed": true }], @@ -224,13 +226,13 @@ TestCase { } function test_keys() { - var control = createTemporaryObject(delayButton, testCase) + let control = createTemporaryObject(delayButton, testCase) verify(control) control.forceActiveFocus() verify(control.activeFocus) - var sequenceSpy = signalSequenceSpy.createObject(control, {target: control}) + let sequenceSpy = signalSequenceSpy.createObject(control, {target: control}) // click sequenceSpy.expectedSequence = [["pressedChanged", { "pressed": true }], @@ -275,8 +277,8 @@ TestCase { sequenceSpy.expectedSequence = [] // Not testing Key_Enter and Key_Return because QGnomeTheme uses them for // pressing buttons and the CI uses the QGnomeTheme platform theme. - var keys = [Qt.Key_Escape, Qt.Key_Tab] - for (var i = 0; i < keys.length; ++i) { + let keys = [Qt.Key_Escape, Qt.Key_Tab] + for (let i = 0; i < keys.length; ++i) { sequenceSpy.reset() keyClick(keys[i]) verify(sequenceSpy.success) @@ -284,10 +286,10 @@ TestCase { } function test_progress() { - var control = createTemporaryObject(delayButton, testCase) + let control = createTemporaryObject(delayButton, testCase) verify(control) - var progressSpy = signalSpy.createObject(control, {target: control, signalName: "progressChanged"}) + let progressSpy = signalSpy.createObject(control, {target: control, signalName: "progressChanged"}) verify(progressSpy.valid) compare(control.progress, 0.0) @@ -297,7 +299,7 @@ TestCase { } function test_baseline() { - var control = createTemporaryObject(delayButton, testCase) + let control = createTemporaryObject(delayButton, testCase) verify(control) compare(control.baselineOffset, control.contentItem.y + control.contentItem.baselineOffset) } diff --git a/tests/auto/quickcontrols/controls/data/tst_dial.qml b/tests/auto/quickcontrols/controls/data/tst_dial.qml index 3fcf8c7e88..1f2b9fdd5c 100644 --- a/tests/auto/quickcontrols/controls/data/tst_dial.qml +++ b/tests/auto/quickcontrols/controls/data/tst_dial.qml @@ -1,5 +1,5 @@ // Copyright (C) 2017 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only import QtQuick import QtTest @@ -27,10 +27,13 @@ TestCase { SignalSpy {} } - function test_instance() { + function init() { + // Fail on any warning that we don't expect. failOnWarning(/.?/) + } - var dial = createTemporaryObject(dialComponent, testCase); + function test_instance() { + let dial = createTemporaryObject(dialComponent, testCase); verify(dial); compare(dial.value, 0.0); compare(dial.from, 0.0); @@ -41,7 +44,7 @@ TestCase { } function test_value() { - var dial = createTemporaryObject(dialComponent, testCase); + let dial = createTemporaryObject(dialComponent, testCase); verify(dial); compare(dial.value, 0.0); @@ -59,7 +62,7 @@ TestCase { } function test_range() { - var dial = createTemporaryObject(dialComponent, testCase); + let dial = createTemporaryObject(dialComponent, testCase); verify(dial); dial.from = 0; @@ -94,7 +97,7 @@ TestCase { } function test_inverted() { - var dial = createTemporaryObject(dialComponent, testCase, { from: 1.0, to: -1.0 }); + let dial = createTemporaryObject(dialComponent, testCase, { from: 1.0, to: -1.0 }); verify(dial); compare(dial.from, 1.0); compare(dial.to, -1.0); @@ -120,7 +123,7 @@ TestCase { } function test_pressed() { - var dial = createTemporaryObject(dialComponent, testCase); + let dial = createTemporaryObject(dialComponent, testCase); verify(dial); pressSpy.target = dial; @@ -135,7 +138,7 @@ TestCase { verify(!dial.pressed); compare(pressSpy.count, 2); - var touch = touchEvent(dial); + let touch = touchEvent(dial); touch.press(0).commit(); verify(dial.pressed); compare(pressSpy.count, 3); @@ -160,7 +163,7 @@ TestCase { } function test_dragging(data) { - var dial = createTemporaryObject(dialComponent, testCase); + let dial = createTemporaryObject(dialComponent, testCase); verify(dial); dial.wrap = true; @@ -172,10 +175,10 @@ TestCase { valueSpy.target = dial; verify(valueSpy.valid); - var moveSpy = createTemporaryObject(signalSpy, testCase, {target: dial, signalName: "moved"}); + let moveSpy = createTemporaryObject(signalSpy, testCase, {target: dial, signalName: "moved"}); verify(moveSpy.valid); - var minimumExpectedValueCount = data.live ? 2 : 1; + let minimumExpectedValueCount = data.live ? 2 : 1; // drag to the left // we always add or subtract 1 to ensure we start the drag from the opposite side @@ -217,55 +220,56 @@ TestCase { } function test_nonWrapping() { - var dial = createTemporaryObject(dialComponent, testCase); + let dial = createTemporaryObject(dialComponent, testCase); verify(dial); compare(dial.wrap, false); dial.value = 0; // Ensure that dragging from bottom left to bottom right doesn't work. - var yPos = dial.height * 0.75; + let yPos = dial.height * 0.75; mousePress(dial, dial.width * 0.25, yPos, Qt.LeftButton); - var positionAtPress = dial.position; + let positionAtPress = dial.position; mouseMove(dial, dial.width * 0.5, yPos); - compare(dial.position, positionAtPress); + verify(dial.position < positionAtPress); mouseMove(dial, dial.width * 0.75, yPos); - compare(dial.position, positionAtPress); + verify(dial.position < positionAtPress); mouseRelease(dial, dial.width * 0.75, yPos, Qt.LeftButton); - compare(dial.position, positionAtPress); + verify(dial.position < positionAtPress); // Try the same thing, but a bit higher. yPos = dial.height * 0.6; mousePress(dial, dial.width * 0.25, yPos, Qt.LeftButton); positionAtPress = dial.position; mouseMove(dial, dial.width * 0.5, yPos); - compare(dial.position, positionAtPress); + verify(dial.position < positionAtPress); mouseMove(dial, dial.width * 0.75, yPos); - compare(dial.position, positionAtPress); + verify(dial.position < positionAtPress); mouseRelease(dial, dial.width * 0.75, yPos, Qt.LeftButton); - compare(dial.position, positionAtPress); + verify(dial.position < positionAtPress); // Going from below the center of the dial to above it should work (once it gets above the center). mousePress(dial, dial.width * 0.25, dial.height * 0.75, Qt.LeftButton); positionAtPress = dial.position; mouseMove(dial, dial.width * 0.5, dial.height * 0.6); - compare(dial.position, positionAtPress); - mouseMove(dial, dial.width * 0.75, dial.height * 0.4); + verify(dial.position < positionAtPress); + mouseMove(dial, dial.width * 0.5, dial.height * 0.4); //move over the top + mouseMove(dial, dial.width * 0.75, dial.height * 0.6); //and back down again verify(dial.position > positionAtPress); mouseRelease(dial, dial.width * 0.75, dial.height * 0.3, Qt.LeftButton); verify(dial.position > positionAtPress); } function test_touch() { - var dial = createTemporaryObject(dialComponent, testCase); + let dial = createTemporaryObject(dialComponent, testCase); verify(dial); - var touch = touchEvent(dial); + let touch = touchEvent(dial); // Ensure that dragging from bottom left to bottom right doesn't work. - var yPos = dial.height * 0.75; + let yPos = dial.height * 0.75; touch.press(0, dial, dial.width * 0.25, yPos).commit(); - var positionAtPress = dial.position; + let positionAtPress = dial.position; touch.move(0, dial, dial.width * 0.5, yPos).commit(); compare(dial.position, positionAtPress); touch.move(0, dial, dial.width * 0.75, yPos).commit(); @@ -289,22 +293,23 @@ TestCase { positionAtPress = dial.position; touch.move(0, dial, dial.width * 0.5, dial.height * 0.6).commit(); compare(dial.position, positionAtPress); - touch.move(0, dial, dial.width * 0.75, dial.height * 0.4).commit(); + touch.move(0, dial, dial.width * 0.5, dial.height * 0.4).commit(); //move over the top + touch.move(0, dial, dial.width * 0.75, dial.height * 0.6).commit(); //and back down again verify(dial.position > positionAtPress); touch.release(0, dial, dial.width * 0.75, dial.height * 0.3).commit(); verify(dial.position > positionAtPress); } function test_multiTouch() { - var dial1 = createTemporaryObject(dialComponent, testCase); + let dial1 = createTemporaryObject(dialComponent, testCase); verify(dial1); - var touch = touchEvent(dial1); + let touch = touchEvent(dial1); touch.press(0, dial1).commit().move(0, dial1, dial1.width / 4, dial1.height / 4).commit(); compare(dial1.pressed, true); verify(dial1.position > 0.0); - var pos1Before = dial1.position; + let pos1Before = dial1.position; // second touch point on the same control is ignored touch.stationary(0).press(1, dial1, 0, 0).commit() @@ -313,7 +318,7 @@ TestCase { compare(dial1.pressed, true); compare(dial1.position, pos1Before); - var dial2 = createTemporaryObject(dialComponent, testCase, {y: dial1.height}); + let dial2 = createTemporaryObject(dialComponent, testCase, {y: dial1.height}); verify(dial2); // press the second dial @@ -322,7 +327,7 @@ TestCase { compare(dial2.position, 0.0); pos1Before = dial1.position; - var pos2Before = dial2.position; + let pos2Before = dial2.position; // move both dials touch.move(0, dial1).move(2, dial2, dial2.width / 4, dial2.height / 4).commit(); @@ -354,19 +359,19 @@ TestCase { } function test_keyboardNavigation() { - var dial = createTemporaryObject(dialComponent, testCase); + let dial = createTemporaryObject(dialComponent, testCase); verify(dial); - var focusScope = createTemporaryObject(focusTest, testCase); + let focusScope = createTemporaryObject(focusTest, testCase); verify(focusScope); - var moveCount = 0; + let moveCount = 0; // Tests that we've accepted events that we're interested in. parentEventSpy.target = focusScope; parentEventSpy.signalName = "receivedKeyPress"; - var moveSpy = createTemporaryObject(signalSpy, testCase, {target: dial, signalName: "moved"}); + let moveSpy = createTemporaryObject(signalSpy, testCase, {target: dial, signalName: "moved"}); verify(moveSpy.valid); dial.parent = focusScope; @@ -382,10 +387,10 @@ TestCase { 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) { + let oldValue = 0.0; + let keyPairs = [[Qt.Key_Left, Qt.Key_Right], [Qt.Key_Down, Qt.Key_Up]]; + for (let keyPairIndex = 0; keyPairIndex < 2; ++keyPairIndex) { + for (let i = 1; i <= 10; ++i) { oldValue = dial.value; keyClick(keyPairs[keyPairIndex][1]); compare(parentEventSpy.count, 0); @@ -396,7 +401,7 @@ TestCase { compare(dial.value, dial.to); - for (i = 10; i > 0; --i) { + for (let i = 10; i > 0; --i) { oldValue = dial.value; keyClick(keyPairs[keyPairIndex][0]); compare(parentEventSpy.count, 0); @@ -434,7 +439,7 @@ TestCase { { tag: "NoSnap", snapMode: Dial.NoSnap, from: 0, to: 2, values: [0, 0, 1], positions: [0, 0.5, 0.5] }, { tag: "SnapAlways (0..2)", snapMode: Dial.SnapAlways, from: 0, to: 2, values: [0.0, 0.0, 1.0], positions: [0.0, 0.5, 0.5] }, { tag: "SnapAlways (1..3)", snapMode: Dial.SnapAlways, from: 1, to: 3, values: [1.0, 1.0, 2.0], positions: [0.0, 0.5, 0.5] }, - { tag: "SnapAlways (-1..1)", snapMode: Dial.SnapAlways, from: -1, to: 1, values: [0.0, 0.0, 0.0], positions: [0.5, 0.5, 0.5] }, + { tag: "SnapAlways (-1..1)", snapMode: Dial.SnapAlways, from: -1, to: 1, values: [0.0, 0.0, 0.0], positions: [immediate ? 0.0 : 0.5, 0.5, 0.5] }, { tag: "SnapAlways (1..-1)", snapMode: Dial.SnapAlways, from: 1, to: -1, values: [1.0, 1.0, 0.0], positions: [0.0, 0.5, 0.5] }, { tag: "SnapOnRelease (0..2)", snapMode: Dial.SnapOnRelease, from: 0, to: 2, values: [0.0, 0.0, 1.0], positions: [0.0, 0.5, 0.5] }, { tag: "SnapOnRelease (1..3)", snapMode: Dial.SnapOnRelease, from: 1, to: 3, values: [1.0, 1.0, 2.0], positions: [0.0, 0.5, 0.5] }, @@ -448,7 +453,7 @@ TestCase { } function test_snapMode_mouse(data) { - var dial = createTemporaryObject(dialComponent, testCase, {live: false}); + let dial = createTemporaryObject(dialComponent, testCase, {live: false}); verify(dial); dial.snapMode = data.snapMode; @@ -456,7 +461,7 @@ TestCase { dial.to = data.to; dial.stepSize = 0.2; - var fuzz = 0.055; + let fuzz = 0.055; mousePress(dial, dial.width * 0.25, dial.height * 0.75); fuzzyCompare(dial.value, data.values[0], fuzz); @@ -476,7 +481,7 @@ TestCase { } function test_snapMode_touch(data) { - var dial = createTemporaryObject(dialComponent, testCase, {live: false}); + let dial = createTemporaryObject(dialComponent, testCase, {live: false}); verify(dial); dial.snapMode = data.snapMode; @@ -484,9 +489,9 @@ TestCase { dial.to = data.to; dial.stepSize = 0.2; - var fuzz = 0.05; + let fuzz = 0.05; - var touch = touchEvent(dial); + let touch = touchEvent(dial); touch.press(0, dial, dial.width * 0.25, dial.height * 0.75).commit() compare(dial.value, data.values[0]); compare(dial.position, data.positions[0]); @@ -502,13 +507,13 @@ TestCase { function test_wheel_data() { return [ - { tag: "horizontal", orientation: Qt.Horizontal, dx: 120, dy: 0 }, - { tag: "vertical", orientation: Qt.Vertical, dx: 0, dy: 120 } + { tag: "horizontal", dx: 120, dy: 0 }, + { tag: "vertical", dx: 0, dy: 120 } ] } function test_wheel(data) { - var control = createTemporaryObject(dialComponent, testCase, {wheelEnabled: true, orientation: data.orientation}) + let control = createTemporaryObject(dialComponent, testCase, {wheelEnabled: true}) verify(control) compare(control.value, 0.0) @@ -546,7 +551,7 @@ TestCase { } function test_nullHandle() { - var control = createTemporaryObject(dialComponent, testCase) + let control = createTemporaryObject(dialComponent, testCase) verify(control) control.handle = null @@ -562,7 +567,7 @@ TestCase { if (inputEventType === "mouseInput") { mouseMove(control, x, y); } else { - var touch = touchEvent(control); + let touch = touchEvent(control); touch.move(0, control, x, y).commit(); } } @@ -571,7 +576,7 @@ TestCase { if (inputEventType === "mouseInput") { mousePress(control, x, y); } else { - var touch = touchEvent(control); + let touch = touchEvent(control); touch.press(0, control, x, y).commit(); } } @@ -580,13 +585,13 @@ TestCase { if (inputEventType === "mouseInput") { mouseRelease(control, x, y); } else { - var touch = touchEvent(control); + let touch = touchEvent(control); touch.release(0, control, x, y).commit(); } } function test_horizontalAndVertical_data() { - var data = [ + let data = [ { eventType: "mouseInput", inputMode: Dial.Vertical, moveToX: 0.5, moveToY: 0.25, expectedPosition: 0.125 }, // Horizontal movement should have no effect on a vertical dial. { eventType: "mouseInput", inputMode: Dial.Vertical, moveToX: 2.0, moveToY: 0.25, expectedPosition: 0.125 }, @@ -612,15 +617,15 @@ TestCase { ]; // Do the same tests for touch by copying the mouse tests and adding them to the end of the array. - var mouseTestCount = data.length; - for (var i = mouseTestCount; i < mouseTestCount * 2; ++i) { + let mouseTestCount = data.length; + for (let i = mouseTestCount; i < mouseTestCount * 2; ++i) { // Shallow-copy the object. data[i] = JSON.parse(JSON.stringify(data[i - mouseTestCount])); data[i].eventType = "touchInput"; } - for (i = 0; i < data.length; ++i) { - var row = data[i]; + for (let i = 0; i < data.length; ++i) { + let row = data[i]; row.tag = "eventType=" + row.eventType + ", " + "inputMode=" + (row.inputMode === Dial.Vertical ? "Vertical" : "Horizontal") + ", " + "moveToX=" + row.moveToX + ", moveToY=" + row.moveToY + ", " @@ -631,7 +636,7 @@ TestCase { } function test_horizontalAndVertical(data) { - var control = createTemporaryObject(dialComponent, testCase, { inputMode: data.inputMode }); + let control = createTemporaryObject(dialComponent, testCase, { inputMode: data.inputMode }); verify(control); press(data.eventType, control); @@ -648,7 +653,7 @@ TestCase { } function test_integerStepping() { - var dial = createTemporaryObject(dialComponent, testCase) + let dial = createTemporaryObject(dialComponent, testCase) verify(dial) dial.from = 1 @@ -661,4 +666,202 @@ TestCase { keyClick(Qt.Key_Right) } } + + function test_startEndAngle_data() { + return [ + { + tag: "Default wrap", startAngle: -140, endAngle: 140, from: 0, to: 1, wrap: true, + x: [0.49, 0.25, 0.5, 0.75, 0.51, 0.49, 0.51], + y: [0.99, 0.5, 0.01, 0.5, 0.99, 0.99, 0.99], + values: [0.0, 0.5-0.32, 0.5, 0.5+0.32, 1.0, 0.0, 1.0], //140/90*0.5 = 0.32 + angles: [-140.0, -90.0, 0.0, 90.0, 140.0, -140.0, 140.0], + wrapClockwise: 1, + wrapCounterClockwise: 1 + }, + { + tag: "-30..30 wrap", startAngle: -30, endAngle: 30, from: 0, to: 1, wrap: true, + x: [0.49, 0.25, 0.5, 0.75, 0.51, 0.49, 0.51], + y: [0.99, 0.5, 0.01, 0.5, 0.99, 0.99, 0.99], + values: [0.0, 0.0, 0.5, 1.0, 1.0, 0.0, 1.0], + angles: [-30.0, -30.0, 0.0, 30.0, 30.0, -30.0, 30.0], + wrapClockwise: 0, //no wrap if angle < 180 + wrapCounterClockwise: 0 + }, + { + tag: "-180..180 wrap", startAngle: -180, endAngle: 180, from: 0, to: 1, wrap: true, + x: [0.49, 0.25, 0.5, 0.75, 0.51, 0.49, 0.51], + y: [0.99, 0.5, 0.01, 0.5, 0.99, 0.99, 0.99], + values: [0.0, 0.25, 0.5, 0.75, 1.0, 0.0, 1.0], + angles: [-180.0, -90.0, 0.0, 90.0, 180.0, -180.0, 180.0], + wrapClockwise: 1, + wrapCounterClockwise: 1 + }, + { + tag: "90..360 wrap", startAngle: 90, endAngle: 360, from: 0, to: 1, wrap: true, + x: [0.49, 0.25, 0.5, 0.75, 0.51, 0.49, 0.5], + y: [0.99, 0.5, 0.01, 0.5, 0.99, 0.99, 0.01], + values: [0.33, 0.66, 1.0, 0.0, 0.33, 0.33, 1.0], + angles: [180.0, 270.0, 360.0, 90.0, 180.0, 180.0, 360.0], + wrapClockwise: 1, + wrapCounterClockwise: 1 + }, + { + tag: "90..450 wrap", startAngle: 90, endAngle: 450, from: 0, to: 1, wrap: true, + x: [0.49, 0.25, 0.5, 0.75, 0.75, 0.51, 0.49, 0.75, 0.75], + y: [0.99, 0.5, 0.01, 0.49, 0.501, 0.99, 0.99, 0.49, 0.501], + values: [0.25, 0.5, 0.75, 1.0, 0.0, 0.25, 0.25, 1.0, 0.0], + angles: [180.0, 270.0, 360.0, 450.0, 90.0, 180.0, 180.0, 450.0, 90.0], + wrapClockwise: 2, + wrapCounterClockwise: 1 + }, + { + tag: "Default nowrap", startAngle: -140, endAngle: 140, from: 0, to: 1, wrap: false, + x: [0.49, 0.25, 0.5, 0.75, 0.51, 0.49], + y: [0.99, 0.5, 0.01, 0.5, 0.99, 0.99], + values: [0.0, 0.5-0.32, 0.5, 0.5+0.32, 1.0, 1.0], //140/90*0.5 = 0.32 + angles: [-140.0, -90.0, 0.0, 90.0, 140.0, 140.0], + wrapClockwise: 0, + wrapCounterClockwise: 0 + }, + { + tag: "-30..30 nowrap", startAngle: -30, endAngle: 30, from: 0, to: 1, wrap: false, + x: [0.49, 0.25, 0.5, 0.75, 0.51, 0.49], + y: [0.99, 0.5, 0.01, 0.5, 0.99, 0.99], + values: [0.0, 0.0, 0.5, 1.0, 1.0, 1.0], + angles: [-30.0, -30.0, 0.0, 30.0, 30.0, 30.0], + wrapClockwise: 0, + wrapCounterClockwise: 0 + }, + { + tag: "-180..180 nowrap", startAngle: -180, endAngle: 180, from: 0, to: 1, wrap: false, + x: [0.49, 0.25, 0.5, 0.75, 0.51, 0.49], + y: [0.99, 0.5, 0.01, 0.5, 0.99, 0.99], + values: [0.0, 0.25, 0.5, 0.75, 1.0, 1.0], + angles: [-180.0, -90.0, 0.0, 90.0, 180.0, 180.0], + wrapClockwise: 0, + wrapCounterClockwise: 0 + }, + { + tag: "90..360 nowrap", startAngle: 90, endAngle: 360, from: 0, to: 1, wrap: false, + x: [0.49, 0.25, 0.5, 0.75, 0.51, 0.49], + y: [0.99, 0.5, 0.01, 0.5, 0.99, 0.99], + values: [0.33, 0.66, 1.0, 1.0, 1.0, 1.0], + angles: [180.0, 270.0, 360.0, 360.0, 360.0, 360.0], + wrapClockwise: 0, + wrapCounterClockwise: 0 + } + ] + } + + function test_startEndAngle(data) { + let dial = createTemporaryObject(dialComponent, testCase) + verify(dial) + + dial.startAngle = data.startAngle + dial.endAngle = data.endAngle + dial.from = data.from + dial.to = data.to + //Give a defined start in case wrap = true + dial.value = data.values[0] + dial.wrap = data.wrap + + compare(dial.startAngle, data.startAngle) + compare(dial.endAngle, data.endAngle) + + let wrappedSpy = signalSpy.createObject(dial, {target: dial, signalName: "wrapped"}) + verify(wrappedSpy.valid) + + for (let i = 0; i < data.x.length; i++) { + mousePress(dial, dial.width * data.x[i], dial.height * 0.5 + dial.width * ( data.y[i] - 0.5)) + fuzzyCompare(dial.angle, data.angles[i], 3.0) + fuzzyCompare(dial.value, data.values[i], 0.1) + } + + let clockwiseCount = 0 + let counterClockwiseCount = 0 + for (let i = 0; i < wrappedSpy.count; i++) { + if (wrappedSpy.signalArguments[i][0] == 0) + clockwiseCount++; + else + counterClockwiseCount++; + } + + compare(clockwiseCount, data.wrapClockwise) + compare(counterClockwiseCount, data.wrapCounterClockwise) + } + + function test_startEndAngleWarnings(data) { + let dial = createTemporaryObject(dialComponent, testCase) + verify(dial) + + dial.startAngle = -180. + dial.endAngle = 180. + + //provoke warning + ignoreWarning(new RegExp("Changing endAngle to avoid overlaps")) + dial.startAngle = -270. + dial.endAngle = 90. + + compare(dial.startAngle, -270.) + compare(dial.endAngle, 90.) + + + dial.startAngle = -180. + dial.endAngle = 180. + + //provoke warning + ignoreWarning(new RegExp("Changing startAngle to avoid overlaps")) + dial.endAngle = 270. + dial.startAngle = -90. + + compare(dial.startAngle, -90.) + compare(dial.endAngle, 270.) + + { + // Should not warn since we delay the setting of start and end angles to avoid + // binding order evaluation conflicts. + let dial = createTemporaryObject(dialComponent, testCase, { startAngle: -10, endAngle: 300 }) + verify(dial) + compare(dial.startAngle, -10.) + compare(dial.endAngle, 300.) + } + } + + function test_notSquareGeometry() { + let dial = createTemporaryObject(dialComponent, testCase) + verify(dial); + if (!dial.handle) { + skip("Test cannot run on styles where handle == null (macOS style)") + } + dial.from = 0 + dial.to = 1 + dial.live = true + dial.wrap = true + dial.startAngle = -180 + dial.endAngle = 180 + + // Dial input handling always assumes that the dial is in the *center*. + // Instantiate a Dial with a geometries of 400x100 and then 100x400 + // Some styles always could wrongly align the Dial background and handle in the topLeft + // corner. Pressing in the handle would cause the Dial to move because the dial + // assumes that the "Dial circle" is center aligned in its geometry. + for (let pass = 0; pass < 2; ++pass) { + if (pass === 0) { + dial.width = testCase.width + dial.height = 100 + } else { + dial.width = 100 + dial.height = testCase.height + } + + let val = pass * 0.25 + dial.value = val + // find coordinates in the middle of the handle + let pt2 = dial.mapFromItem(dial.handle, dial.handle.width/2, dial.handle.height/2) + // press the knob in the middle. It shouldn't move (except from due to rounding errors) + mousePress(dial, pt2.x, pt2.y) + fuzzyCompare(dial.value, val, 0.1) + } + } + } diff --git a/tests/auto/quickcontrols/controls/data/tst_dialog.qml b/tests/auto/quickcontrols/controls/data/tst_dialog.qml index 76ff95a32a..8c888be98f 100644 --- a/tests/auto/quickcontrols/controls/data/tst_dialog.qml +++ b/tests/auto/quickcontrols/controls/data/tst_dialog.qml @@ -1,5 +1,5 @@ // Copyright (C) 2017 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only import QtQuick import QtQuick.Window @@ -39,13 +39,12 @@ TestCase { } function init() { + failOnWarning(/.?/) tryCompare(testCase.Window.window, "active", true) } function test_defaults() { - failOnWarning(/.?/) - - var control = createTemporaryObject(dialog, testCase) + let control = createTemporaryObject(dialog, testCase) verify(control) verify(control.header) verify(control.footer) @@ -54,9 +53,9 @@ TestCase { } function test_accept() { - var control = createTemporaryObject(dialog, testCase) + let control = createTemporaryObject(dialog, testCase) - var openedSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "opened"}) + let openedSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "opened"}) verify(openedSpy.valid) control.open() @@ -64,10 +63,10 @@ TestCase { compare(openedSpy.count, 1) verify(control.visible) - var acceptedSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "accepted"}) + let acceptedSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "accepted"}) verify(acceptedSpy.valid) - var closedSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "closed"}) + let closedSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "closed"}) verify(closedSpy.valid) control.accept() @@ -80,9 +79,9 @@ TestCase { } function test_reject() { - var control = createTemporaryObject(dialog, testCase) + let control = createTemporaryObject(dialog, testCase) - var openedSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "opened"}) + let openedSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "opened"}) verify(openedSpy.valid) control.open() @@ -90,10 +89,10 @@ TestCase { compare(openedSpy.count, 1) verify(control.visible) - var rejectedSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "rejected"}) + let rejectedSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "rejected"}) verify(rejectedSpy.valid) - var closedSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "closed"}) + let closedSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "closed"}) verify(closedSpy.valid) control.reject() @@ -127,6 +126,8 @@ TestCase { control.closePolicy = Popup.CloseOnPressOutside control.open() verify(control.visible) + // wait for enter transitions to finish + openedSpy.wait() mousePress(testCase, 1, 1) compare(rejectedSpy.count, 3) @@ -145,6 +146,7 @@ TestCase { control.closePolicy = Popup.CloseOnReleaseOutside control.open() verify(control.visible) + openedSpy.wait() mousePress(testCase, 1, 1) compare(rejectedSpy.count, 3) @@ -165,46 +167,46 @@ TestCase { } function test_buttonBox(data) { - var control = createTemporaryObject(dialog, testCase) + let control = createTemporaryObject(dialog, testCase) if (data.custom) control.footer = buttonBox.createObject(testCase) control.standardButtons = Dialog.Ok | Dialog.Cancel - var box = control.footer + let box = control.footer verify(box) compare(box.standardButtons, Dialog.Ok | Dialog.Cancel) - var acceptedSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "accepted"}) + let acceptedSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "accepted"}) verify(acceptedSpy.valid) box.accepted() compare(acceptedSpy.count, 1) - var rejectedSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "rejected"}) + let rejectedSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "rejected"}) verify(rejectedSpy.valid) box.rejected() compare(rejectedSpy.count, 1) } function test_qtbug71444() { - var control = createTemporaryObject(qtbug71444, testCase) + let control = createTemporaryObject(qtbug71444, testCase) verify(control) } function test_standardButtons() { - var control = createTemporaryObject(dialog, testCase) + let control = createTemporaryObject(dialog, testCase) control.standardButtons = Dialog.Ok - var box = control.footer ? control.footer : control.header + let box = control.footer ? control.footer : control.header verify(box) compare(box.count, 1) - var okButton = box.itemAt(0) + let okButton = box.itemAt(0) verify(okButton) compare(okButton.text.toUpperCase(), "OK") control.standardButtons = Dialog.Cancel compare(box.count, 1) - var cancelButton = control.footer.itemAt(0) + let cancelButton = control.footer.itemAt(0) verify(cancelButton) compare(cancelButton.text.toUpperCase(), "CANCEL") @@ -227,10 +229,10 @@ TestCase { } function test_layout() { - var control = createTemporaryObject(dialog, testCase, {width: 100, height: 100}) + let control = createTemporaryObject(dialog, testCase, {width: 100, height: 100}) verify(control) - var openedSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "opened"}) + let openedSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "opened"}) verify(openedSpy.valid) control.open() @@ -300,6 +302,7 @@ TestCase { compare(control.implicitHeight, control.contentItem.implicitHeight + control.topPadding + control.bottomPadding + control.header.implicitHeight + control.footer.implicitHeight) + control.footer.implicitWidth = 0 control.header.implicitWidth = 150 compare(control.implicitWidth, control.header.implicitWidth) @@ -320,10 +323,10 @@ TestCase { } function test_spacing(data) { - var control = createTemporaryObject(dialog, testCase, {spacing: 20, width: 100, height: 100}) + let control = createTemporaryObject(dialog, testCase, {spacing: 20, width: 100, height: 100}) verify(control) - var openedSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "opened"}) + let openedSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "opened"}) verify(openedSpy.valid) control.open() @@ -377,14 +380,14 @@ TestCase { } function test_signals(data) { - var control = createTemporaryObject(dialog, testCase) + let control = createTemporaryObject(dialog, testCase) verify(control) control.standardButtons = data.standardButton - var button = control.standardButton(data.standardButton) + let button = control.standardButton(data.standardButton) verify(button) - var buttonSpy = signalSpy.createObject(control.contentItem, {target: control, signalName: data.signalName}) + let buttonSpy = signalSpy.createObject(control.contentItem, {target: control, signalName: data.signalName}) verify(buttonSpy.valid) button.clicked() @@ -428,7 +431,7 @@ TestCase { if (Qt.platform.pluginName === "offscreen") skip("QTBUG-89909") - var window = createTemporaryObject(qtbug85884, testCase) + let window = createTemporaryObject(qtbug85884, testCase) verify(window) tryCompare(window, "focusItemActiveFocus", true) diff --git a/tests/auto/quickcontrols/controls/data/tst_dialogbuttonbox.qml b/tests/auto/quickcontrols/controls/data/tst_dialogbuttonbox.qml index 6eb339a192..2fa26881bc 100644 --- a/tests/auto/quickcontrols/controls/data/tst_dialogbuttonbox.qml +++ b/tests/auto/quickcontrols/controls/data/tst_dialogbuttonbox.qml @@ -1,5 +1,5 @@ // Copyright (C) 2017 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only import QtQuick import QtTest @@ -28,10 +28,12 @@ TestCase { SignalSpy { } } - function test_defaults() { + function init() { failOnWarning(/.?/) + } - var control = createTemporaryObject(buttonBox, testCase) + function test_defaults() { + let control = createTemporaryObject(buttonBox, testCase) verify(control) compare(control.count, 0) verify(control.delegate) @@ -39,19 +41,19 @@ TestCase { } function test_standardButtons() { - var control = createTemporaryObject(buttonBox, testCase) + let control = createTemporaryObject(buttonBox, testCase) verify(control) compare(control.count, 0) control.standardButtons = DialogButtonBox.Ok compare(control.count, 1) - var okButton = control.itemAt(0) + let okButton = control.itemAt(0) verify(okButton) compare(okButton.text.toUpperCase(), "OK") control.standardButtons = DialogButtonBox.Cancel compare(control.count, 1) - var cancelButton = control.itemAt(0) + let cancelButton = control.itemAt(0) verify(cancelButton) compare(cancelButton.text.toUpperCase(), "CANCEL") @@ -79,21 +81,21 @@ TestCase { } function test_attached() { - var control = createTemporaryObject(buttonBox, testCase) + let control = createTemporaryObject(buttonBox, testCase) verify(control) control.standardButtons = DialogButtonBox.Ok - var okButton = control.itemAt(0) + let okButton = control.itemAt(0) compare(okButton.DialogButtonBox.buttonBox, control) compare(okButton.DialogButtonBox.buttonRole, DialogButtonBox.AcceptRole) - var saveButton = button.createObject(control, {text: "Save"}) + let saveButton = button.createObject(control, {text: "Save"}) compare(saveButton.DialogButtonBox.buttonBox, control) compare(saveButton.DialogButtonBox.buttonRole, DialogButtonBox.InvalidRole) saveButton.DialogButtonBox.buttonRole = DialogButtonBox.AcceptRole compare(saveButton.DialogButtonBox.buttonRole, DialogButtonBox.AcceptRole) - var closeButton = createTemporaryObject(button, null, {text: "Save"}) + let closeButton = createTemporaryObject(button, null, {text: "Save"}) compare(closeButton.DialogButtonBox.buttonBox, null) compare(closeButton.DialogButtonBox.buttonRole, DialogButtonBox.InvalidRole) closeButton.DialogButtonBox.buttonRole = DialogButtonBox.DestructiveRole @@ -131,18 +133,18 @@ TestCase { } function test_signals(data) { - var control = createTemporaryObject(buttonBox, testCase) + let control = createTemporaryObject(buttonBox, testCase) verify(control) control.standardButtons = data.standardButton compare(control.count, 1) - var button = control.itemAt(0) + let button = control.itemAt(0) verify(button) compare(button.DialogButtonBox.buttonRole, data.buttonRole) - var clickedSpy = signalSpy.createObject(control, {target: control, signalName: "clicked"}) + let clickedSpy = signalSpy.createObject(control, {target: control, signalName: "clicked"}) verify(clickedSpy.valid) - var roleSpy = signalSpy.createObject(control, {target: control, signalName: data.signalName}) + let roleSpy = signalSpy.createObject(control, {target: control, signalName: data.signalName}) verify(roleSpy.valid) button.clicked() @@ -162,16 +164,16 @@ TestCase { } function test_buttonLayout(data) { - var control = createTemporaryObject(buttonBox, testCase, {buttonLayout: data.buttonLayout, standardButtons: DialogButtonBox.Ok|DialogButtonBox.Cancel}) + let control = createTemporaryObject(buttonBox, testCase, {buttonLayout: data.buttonLayout, standardButtons: DialogButtonBox.Ok|DialogButtonBox.Cancel}) verify(control) compare(control.count, 2) - var button1 = control.itemAt(0) + let button1 = control.itemAt(0) verify(button1) compare(button1.DialogButtonBox.buttonRole, data.button1Role) - var button2 = control.itemAt(1) + let button2 = control.itemAt(1) verify(button2) compare(button2.DialogButtonBox.buttonRole, data.button2Role) } @@ -185,16 +187,16 @@ TestCase { // QTBUG-59719 function test_implicitSize(data) { - var control = createTemporaryObject(buttonBox, testCase, {standardButtons: data.standardButtons}) + let control = createTemporaryObject(buttonBox, testCase, {standardButtons: data.standardButtons}) verify(control) - var listView = control.contentItem + let listView = control.contentItem verify(listView && listView.hasOwnProperty("contentWidth")) waitForRendering(listView) - var implicitContentWidth = control.leftPadding + control.rightPadding - for (var i = 0; i < listView.contentItem.children.length; ++i) { - var button = listView.contentItem.children[i] + let implicitContentWidth = control.leftPadding + control.rightPadding + for (let i = 0; i < listView.contentItem.children.length; ++i) { + let button = listView.contentItem.children[i] if (!button.hasOwnProperty("text")) continue implicitContentWidth += button.implicitWidth @@ -217,14 +219,14 @@ TestCase { } function test_buttonSize() { - var control = createTemporaryObject(okCancelBox, testCase) + let control = createTemporaryObject(okCancelBox, testCase) verify(control) - var okButton = control.itemAt(0) + let okButton = control.itemAt(0) verify(okButton) verify(okButton.width > 0) - var cancelButton = control.itemAt(1) + let cancelButton = control.itemAt(1) verify(cancelButton) verify(cancelButton.width > 0) @@ -232,14 +234,14 @@ TestCase { } function test_oneButtonInFixedWidthBox() { - var control = createTemporaryObject(buttonBox, testCase, + let control = createTemporaryObject(buttonBox, testCase, { width: 400, standardButtons: Dialog.Close }) verify(control) - var listView = control.contentItem + let listView = control.contentItem waitForRendering(listView) - var button = control.itemAt(0) + let button = control.itemAt(0) verify(button) // The button should never go outside of the box. @@ -280,14 +282,14 @@ TestCase { // QTBUG-73860 function test_oneButtonAlignedRightInImplicitWidthBox() { - var dialog = createTemporaryObject(dialogComponent, testCase) + let dialog = createTemporaryObject(dialogComponent, testCase) verify(dialog) - var box = dialog.footer - var listView = box.contentItem + let box = dialog.footer + let listView = box.contentItem waitForRendering(listView) - var button = box.itemAt(0) + let button = box.itemAt(0) verify(button) // The button should never go outside of the box. @@ -353,13 +355,13 @@ TestCase { // QTBUG-72886 function test_changeCustomButtonText(data) { - var control = createTemporaryObject(data.component, testCase, {}) + let control = createTemporaryObject(data.component, testCase, {}) verify(control) - var listView = control.contentItem + let listView = control.contentItem waitForRendering(listView) - var button = control.okButton + let button = control.okButton verify(button) button.text = "some longer text"; @@ -519,9 +521,9 @@ TestCase { } function test_contentItemDeletionOrder() { - var control1 = createTemporaryObject(contentItemDeletionOrder1, testCase) + let control1 = createTemporaryObject(contentItemDeletionOrder1, testCase) verify(control1) - var control2 = createTemporaryObject(contentItemDeletionOrder2, testCase) + let control2 = createTemporaryObject(contentItemDeletionOrder2, testCase) verify(control2) } @@ -560,9 +562,9 @@ TestCase { } function test_backgroundDeletionOrder() { - var control1 = createTemporaryObject(backgroundDeletionOrder1, testCase) + let control1 = createTemporaryObject(backgroundDeletionOrder1, testCase) verify(control1) - var control2 = createTemporaryObject(backgroundDeletionOrder2, testCase) + let control2 = createTemporaryObject(backgroundDeletionOrder2, testCase) verify(control2) } } diff --git a/tests/auto/quickcontrols/controls/data/tst_frame.qml b/tests/auto/quickcontrols/controls/data/tst_frame.qml index bef46f7650..141940edc3 100644 --- a/tests/auto/quickcontrols/controls/data/tst_frame.qml +++ b/tests/auto/quickcontrols/controls/data/tst_frame.qml @@ -1,5 +1,5 @@ // Copyright (C) 2017 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only import QtQuick import QtTest @@ -52,10 +52,12 @@ TestCase { } } - function test_empty() { + function init() { failOnWarning(/.?/) + } - var control = createTemporaryObject(frame, testCase) + function test_empty() { + let control = createTemporaryObject(frame, testCase) verify(control) verify(control.contentItem) @@ -66,7 +68,7 @@ TestCase { } function test_oneChild() { - var control = createTemporaryObject(oneChildFrame, testCase) + let control = createTemporaryObject(oneChildFrame, testCase) verify(control) compare(control.contentWidth, 100) @@ -78,7 +80,7 @@ TestCase { } function test_twoChildren() { - var control = createTemporaryObject(twoChildrenFrame, testCase) + let control = createTemporaryObject(twoChildrenFrame, testCase) verify(control) compare(control.contentWidth, 0) @@ -90,7 +92,7 @@ TestCase { } function test_contentItem() { - var control = createTemporaryObject(contentFrame, testCase) + let control = createTemporaryObject(contentFrame, testCase) verify(control) compare(control.contentWidth, 100) diff --git a/tests/auto/quickcontrols/controls/data/tst_groupbox.qml b/tests/auto/quickcontrols/controls/data/tst_groupbox.qml index b5867dd956..501870e1bc 100644 --- a/tests/auto/quickcontrols/controls/data/tst_groupbox.qml +++ b/tests/auto/quickcontrols/controls/data/tst_groupbox.qml @@ -1,5 +1,5 @@ // Copyright (C) 2017 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only import QtQuick import QtTest @@ -52,10 +52,12 @@ TestCase { } } - function test_empty() { + function init() { failOnWarning(/.?/) + } - var control = createTemporaryObject(groupBox, testCase) + function test_empty() { + let control = createTemporaryObject(groupBox, testCase) verify(control) verify(control.contentItem) @@ -66,7 +68,7 @@ TestCase { } function test_oneChild() { - var control = createTemporaryObject(oneChildBox, testCase) + let control = createTemporaryObject(oneChildBox, testCase) verify(control) compare(control.contentWidth, 100) @@ -78,7 +80,7 @@ TestCase { } function test_twoChildren() { - var control = createTemporaryObject(twoChildrenBox, testCase) + let control = createTemporaryObject(twoChildrenBox, testCase) verify(control) compare(control.contentWidth, 0) @@ -90,7 +92,7 @@ TestCase { } function test_contentItem() { - var control = createTemporaryObject(contentBox, testCase) + let control = createTemporaryObject(contentBox, testCase) verify(control) compare(control.contentWidth, 100) diff --git a/tests/auto/quickcontrols/controls/data/tst_itemdelegate.qml b/tests/auto/quickcontrols/controls/data/tst_itemdelegate.qml index 9d4847b4b1..db78299c25 100644 --- a/tests/auto/quickcontrols/controls/data/tst_itemdelegate.qml +++ b/tests/auto/quickcontrols/controls/data/tst_itemdelegate.qml @@ -1,5 +1,5 @@ // Copyright (C) 2017 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only import QtQuick import QtTest @@ -18,21 +18,23 @@ TestCase { ItemDelegate { } } - function test_defaults() { + function init() { failOnWarning(/.?/) + } + function test_defaults() { let control = createTemporaryObject(itemDelegate, testCase) verify(control) } function test_baseline() { - var control = createTemporaryObject(itemDelegate, testCase) + let control = createTemporaryObject(itemDelegate, testCase) verify(control) compare(control.baselineOffset, control.contentItem.y + control.contentItem.baselineOffset) } function test_highlighted() { - var control = createTemporaryObject(itemDelegate, testCase) + let control = createTemporaryObject(itemDelegate, testCase) verify(control) verify(!control.highlighted) @@ -41,11 +43,11 @@ TestCase { } function test_spacing() { - var control = createTemporaryObject(itemDelegate, testCase, { text: "Some long, long, long text" }) + let control = createTemporaryObject(itemDelegate, testCase, { text: "Some long, long, long text" }) verify(control) verify(control.contentItem.implicitWidth + control.leftPadding + control.rightPadding > control.background.implicitWidth) - var textLabel = findChild(control.contentItem, "label") + let textLabel = findChild(control.contentItem, "label") verify(textLabel) // The implicitWidth of the IconLabel that all buttons use as their contentItem @@ -74,7 +76,7 @@ TestCase { } function test_display(data) { - var control = createTemporaryObject(itemDelegate, testCase, { + let control = createTemporaryObject(itemDelegate, testCase, { text: "ItemDelegate", display: data.display, width: 400, @@ -84,8 +86,8 @@ TestCase { verify(control) compare(control.icon.source, "qrc:/qt-project.org/imports/QtQuick/Controls/Basic/images/check.png") - var iconImage = findChild(control.contentItem, "image") - var textLabel = findChild(control.contentItem, "label") + let iconImage = findChild(control.contentItem, "image") + let textLabel = findChild(control.contentItem, "label") switch (control.display) { case ItemDelegate.IconOnly: diff --git a/tests/auto/quickcontrols/controls/data/tst_label.qml b/tests/auto/quickcontrols/controls/data/tst_label.qml index 853d5ba686..2477ce338d 100644 --- a/tests/auto/quickcontrols/controls/data/tst_label.qml +++ b/tests/auto/quickcontrols/controls/data/tst_label.qml @@ -1,5 +1,5 @@ // Copyright (C) 2017 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only import QtQuick import QtTest @@ -35,10 +35,12 @@ TestCase { SignalSpy { } } - function test_creation() { + function init() { failOnWarning(/.?/) + } - var control = createTemporaryObject(label, testCase) + function test_creation() { + let control = createTemporaryObject(label, testCase) verify(control) } @@ -46,7 +48,7 @@ TestCase { return [ {tag: "bold", value: true}, {tag: "capitalization", value: Font.Capitalize}, - {tag: "family", value: "Courier"}, + {tag: "family", value: "Tahoma"}, {tag: "italic", value: true}, {tag: "strikeout", value: true}, {tag: "underline", value: true}, @@ -56,19 +58,19 @@ TestCase { } function test_font_explicit_attributes(data) { - var control = createTemporaryObject(label, testCase) + let control = createTemporaryObject(label, testCase) verify(control) - var child = label.createObject(control) + let child = label.createObject(control) verify(child) - var controlSpy = signalSpy.createObject(control, {target: control, signalName: "fontChanged"}) + let controlSpy = signalSpy.createObject(control, {target: control, signalName: "fontChanged"}) verify(controlSpy.valid) - var childSpy = signalSpy.createObject(child, {target: child, signalName: "fontChanged"}) + let childSpy = signalSpy.createObject(child, {target: child, signalName: "fontChanged"}) verify(childSpy.valid) - var defaultValue = control.font[data.tag] + let defaultValue = control.font[data.tag] child.font[data.tag] = defaultValue compare(child.font[data.tag], defaultValue) @@ -84,7 +86,7 @@ TestCase { } function test_background() { - var control = createTemporaryObject(backgroundLabel, testCase, {text: "Label"}) + let control = createTemporaryObject(backgroundLabel, testCase, {text: "Label"}) verify(control) compare(control.background.width, control.width) @@ -102,25 +104,25 @@ TestCase { } function test_inset() { - var control = createTemporaryObject(label, testCase, {background: rectangle.createObject(control)}) + let control = createTemporaryObject(label, testCase, {background: rectangle.createObject(testCase)}) verify(control) - var topInsetSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "topInsetChanged"}) + let topInsetSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "topInsetChanged"}) verify(topInsetSpy.valid) - var leftInsetSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "leftInsetChanged"}) + let leftInsetSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "leftInsetChanged"}) verify(leftInsetSpy.valid) - var rightInsetSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "rightInsetChanged"}) + let rightInsetSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "rightInsetChanged"}) verify(rightInsetSpy.valid) - var bottomInsetSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "bottomInsetChanged"}) + let bottomInsetSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "bottomInsetChanged"}) verify(bottomInsetSpy.valid) - var topInsetChanges = 0 - var leftInsetChanges = 0 - var rightInsetChanges = 0 - var bottomInsetChanges = 0 + let topInsetChanges = 0 + let leftInsetChanges = 0 + let rightInsetChanges = 0 + let bottomInsetChanges = 0 compare(control.topInset, 0) compare(control.leftInset, 0) diff --git a/tests/auto/quickcontrols/controls/data/tst_menuitem.qml b/tests/auto/quickcontrols/controls/data/tst_menuitem.qml index d1ed076705..35335ec88d 100644 --- a/tests/auto/quickcontrols/controls/data/tst_menuitem.qml +++ b/tests/auto/quickcontrols/controls/data/tst_menuitem.qml @@ -1,5 +1,5 @@ // Copyright (C) 2017 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only import QtQuick import QtTest @@ -23,21 +23,23 @@ TestCase { Menu { } } - function test_defaults() { + function init() { failOnWarning(/.?/) + } + function test_defaults() { let control = createTemporaryObject(menuItem, testCase) verify(control) } function test_baseline() { - var control = createTemporaryObject(menuItem, testCase) + let control = createTemporaryObject(menuItem, testCase) verify(control) compare(control.baselineOffset, control.contentItem.y + control.contentItem.baselineOffset) } function test_checkable() { - var control = createTemporaryObject(menuItem, testCase) + let control = createTemporaryObject(menuItem, testCase) verify(control) verify(control.hasOwnProperty("checkable")) verify(!control.checkable) @@ -54,7 +56,7 @@ TestCase { } function test_highlighted() { - var control = createTemporaryObject(menuItem, testCase) + let control = createTemporaryObject(menuItem, testCase) verify(control) verify(!control.highlighted) @@ -76,7 +78,7 @@ TestCase { } function test_display(data) { - var control = createTemporaryObject(menuItem, testCase, { + let control = createTemporaryObject(menuItem, testCase, { text: "MenuItem", display: data.display, "icon.source": "qrc:/qt-project.org/imports/QtQuick/Controls/Basic/images/check.png", @@ -85,9 +87,9 @@ TestCase { verify(control) compare(control.icon.source, "qrc:/qt-project.org/imports/QtQuick/Controls/Basic/images/check.png") - var padding = data.mirrored ? control.contentItem.rightPadding : control.contentItem.leftPadding - var iconImage = findChild(control.contentItem, "image") - var textLabel = findChild(control.contentItem, "label") + let padding = data.mirrored ? control.contentItem.rightPadding : control.contentItem.leftPadding + let iconImage = findChild(control.contentItem, "image") + let textLabel = findChild(control.contentItem, "label") switch (control.display) { case MenuItem.IconOnly: @@ -123,14 +125,14 @@ TestCase { } function test_menu() { - var control = createTemporaryObject(menu, testCase) + let control = createTemporaryObject(menu, testCase) verify(control) - var item1 = createTemporaryObject(menuItem, testCase) + let item1 = createTemporaryObject(menuItem, testCase) verify(item1) compare(item1.menu, null) - var item2 = createTemporaryObject(menuItem, testCase) + let item2 = createTemporaryObject(menuItem, testCase) verify(item2) compare(item2.menu, null) diff --git a/tests/auto/quickcontrols/controls/data/tst_monthgrid.qml b/tests/auto/quickcontrols/controls/data/tst_monthgrid.qml index 5b1081675e..d0d66442c0 100644 --- a/tests/auto/quickcontrols/controls/data/tst_monthgrid.qml +++ b/tests/auto/quickcontrols/controls/data/tst_monthgrid.qml @@ -1,5 +1,5 @@ // Copyright (C) 2021 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only import QtQuick import QtQuick.Controls @@ -37,15 +37,17 @@ TestCase { SignalSpy { } } - function test_defaults() { + function init() { failOnWarning(/.?/) + } + function test_defaults() { let control = createTemporaryObject(defaultGrid, testCase) verify(control) } function test_locale() { - var control = delegateGrid.createObject(testCase, {month: 0, year: 2013}) + let control = delegateGrid.createObject(testCase, {month: 0, year: 2013}) compare(control.contentItem.children.length, 6 * 7 + 1) @@ -58,15 +60,15 @@ TestCase { compare(control.locale.name, "en_GB") // M T W T F S S - var en_GB = ["2012-12-31", "2013-01-01", "2013-01-02", "2013-01-03", "2013-01-04", "2013-01-05", "2013-01-06", + let en_GB = ["2012-12-31", "2013-01-01", "2013-01-02", "2013-01-03", "2013-01-04", "2013-01-05", "2013-01-06", "2013-01-07", "2013-01-08", "2013-01-09", "2013-01-10", "2013-01-11", "2013-01-12", "2013-01-13", "2013-01-14", "2013-01-15", "2013-01-16", "2013-01-17", "2013-01-18", "2013-01-19", "2013-01-20", "2013-01-21", "2013-01-22", "2013-01-23", "2013-01-24", "2013-01-25", "2013-01-26", "2013-01-27", "2013-01-28", "2013-01-29", "2013-01-30", "2013-01-31", "2013-02-01", "2013-02-02", "2013-02-03", "2013-02-04", "2013-02-05", "2013-02-06", "2013-02-07", "2013-02-08", "2013-02-09", "2013-02-10"] - for (var i = 0; i < 42; ++i) { - var cellDate = new Date(en_GB[i]) + for (let i = 0; i < 42; ++i) { + let cellDate = new Date(en_GB[i]) compare(control.contentItem.children[i].date.getFullYear(), cellDate.getUTCFullYear()) compare(control.contentItem.children[i].date.getMonth(), cellDate.getUTCMonth()) compare(control.contentItem.children[i].date.getDate(), cellDate.getUTCDate()) @@ -81,15 +83,15 @@ TestCase { compare(control.locale.name, "en_US") // S M T W T F S - var en_US = ["2012-12-30", "2012-12-31", "2013-01-01", "2013-01-02", "2013-01-03", "2013-01-04", "2013-01-05", + let en_US = ["2012-12-30", "2012-12-31", "2013-01-01", "2013-01-02", "2013-01-03", "2013-01-04", "2013-01-05", "2013-01-06", "2013-01-07", "2013-01-08", "2013-01-09", "2013-01-10", "2013-01-11", "2013-01-12", "2013-01-13", "2013-01-14", "2013-01-15", "2013-01-16", "2013-01-17", "2013-01-18", "2013-01-19", "2013-01-20", "2013-01-21", "2013-01-22", "2013-01-23", "2013-01-24", "2013-01-25", "2013-01-26", "2013-01-27", "2013-01-28", "2013-01-29", "2013-01-30", "2013-01-31", "2013-02-01", "2013-02-02", "2013-02-03", "2013-02-04", "2013-02-05", "2013-02-06", "2013-02-07", "2013-02-08", "2013-02-09"] - for (var j = 0; j < 42; ++j) { - cellDate = new Date(en_US[j]) + for (let j = 0; j < 42; ++j) { + let cellDate = new Date(en_US[j]) compare(control.contentItem.children[j].date.getFullYear(), cellDate.getUTCFullYear()) compare(control.contentItem.children[j].date.getMonth(), cellDate.getUTCMonth()) compare(control.contentItem.children[j].date.getDate(), cellDate.getUTCDate()) @@ -103,7 +105,7 @@ TestCase { } function test_range() { - var control = defaultGrid.createObject(testCase) + let control = defaultGrid.createObject(testCase) control.month = 0 compare(control.month, 0) @@ -138,7 +140,7 @@ TestCase { } function test_bce() { - var control = defaultGrid.createObject(testCase) + let control = defaultGrid.createObject(testCase) compare(control.contentItem.children.length, 6 * 7 + 1) @@ -153,14 +155,14 @@ TestCase { compare(control.year, -1) // M T W T F S S - var jan1bce = [27, 28, 29, 30, 31, 1, 2, + let jan1bce = [27, 28, 29, 30, 31, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 1, 2, 3, 4, 5, 6] - for (var i = 0; i < 42; ++i) + for (let i = 0; i < 42; ++i) compare(control.contentItem.children[i].text, jan1bce[i].toString()) // February 1 BCE @@ -170,21 +172,21 @@ TestCase { compare(control.year, -1) // M T W T F S S - var feb1bce = [31, 1, 2, 3, 4, 5, 6, + let feb1bce = [31, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] - for (var j = 0; j < 42; ++j) + for (let j = 0; j < 42; ++j) compare(control.contentItem.children[j].text, feb1bce[j].toString()) control.destroy() } function test_font() { - var control = defaultGrid.createObject(testCase) + let control = defaultGrid.createObject(testCase) verify(control.contentItem.children[0]) @@ -202,24 +204,24 @@ TestCase { } function test_clicked(data) { - var control = createTemporaryObject(defaultGrid, testCase) + let control = createTemporaryObject(defaultGrid, testCase) verify(control) compare(control.contentItem.children.length, 6 * 7 + 1) - var pressedSpy = signalSpy.createObject(control, {target: control, signalName: "pressed"}) + let pressedSpy = signalSpy.createObject(control, {target: control, signalName: "pressed"}) verify(pressedSpy.valid) - var releasedSpy = signalSpy.createObject(control, {target: control, signalName: "released"}) + let releasedSpy = signalSpy.createObject(control, {target: control, signalName: "released"}) verify(releasedSpy.valid) - var clickedSpy = signalSpy.createObject(control, {target: control, signalName: "clicked"}) + let clickedSpy = signalSpy.createObject(control, {target: control, signalName: "clicked"}) verify(clickedSpy.valid) - var touch = touchEvent(control) + let touch = touchEvent(control) - for (var i = 0; i < 42; ++i) { - var cell = control.contentItem.children[i] + for (let i = 0; i < 42; ++i) { + let cell = control.contentItem.children[i] verify(cell) if (data.touch) diff --git a/tests/auto/quickcontrols/controls/data/tst_page.qml b/tests/auto/quickcontrols/controls/data/tst_page.qml index ca816d963b..2396b30dff 100644 --- a/tests/auto/quickcontrols/controls/data/tst_page.qml +++ b/tests/auto/quickcontrols/controls/data/tst_page.qml @@ -1,5 +1,5 @@ // Copyright (C) 2017 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only import QtQuick import QtTest @@ -69,10 +69,12 @@ TestCase { ToolBar { } } - function test_defaults() { + function init() { failOnWarning(/.?/) + } - var control = createTemporaryObject(page, testCase) + function test_defaults() { + let control = createTemporaryObject(page, testCase) verify(control) verify(control.contentItem) @@ -81,9 +83,7 @@ TestCase { } function test_empty() { - failOnWarning(/.?/) - - var control = createTemporaryObject(page, testCase) + let control = createTemporaryObject(page, testCase) verify(control) verify(control.contentItem) @@ -94,7 +94,7 @@ TestCase { } function test_oneChild() { - var control = createTemporaryObject(oneChildPage, testCase) + let control = createTemporaryObject(oneChildPage, testCase) verify(control) compare(control.contentWidth, 100) @@ -106,7 +106,7 @@ TestCase { } function test_twoChildren() { - var control = createTemporaryObject(twoChildrenPage, testCase) + let control = createTemporaryObject(twoChildrenPage, testCase) verify(control) compare(control.contentWidth, 0) @@ -120,7 +120,7 @@ TestCase { } function test_contentItem() { - var control = createTemporaryObject(contentPage, testCase) + let control = createTemporaryObject(contentPage, testCase) verify(control) compare(control.contentWidth, 100) @@ -132,7 +132,7 @@ TestCase { } function test_layout() { - var control = createTemporaryObject(page, testCase, {width: 100, height: 100}) + let control = createTemporaryObject(page, testCase, {width: 100, height: 100}) verify(control) compare(control.width, 100) @@ -220,7 +220,7 @@ TestCase { } function test_spacing(data) { - var control = createTemporaryObject(page, testCase, {spacing: 20, width: 100, height: 100}) + let control = createTemporaryObject(page, testCase, {spacing: 20, width: 100, height: 100}) verify(control) control.contentItem.visible = data.content @@ -246,7 +246,7 @@ TestCase { } function test_headerFooter() { - var control = createTemporaryObject(headerFooterPage, testCase, {width: 100, height: 100}) + let control = createTemporaryObject(headerFooterPage, testCase, {width: 100, height: 100}) verify(control) compare(control.width, 100) @@ -268,5 +268,18 @@ TestCase { compare(control.contentItem.y, control.header.height) compare(control.contentItem.width, control.width) compare(control.contentItem.height, control.height - control.header.height - control.footer.height) + + // swap places and make sure geometry is updated correctly + const oldHeader = control.header + const oldFooter = control.footer + // reset both first, so one item does not end up in two places at once + control.header = null + control.footer = null + control.header = oldFooter + control.footer = oldHeader + verify(control.header.visible) + verify(control.footer.visible) + compare(control.header.y, 0) + compare(control.footer.y, control.height - control.footer.height) } } diff --git a/tests/auto/quickcontrols/controls/data/tst_pageindicator.qml b/tests/auto/quickcontrols/controls/data/tst_pageindicator.qml index 837972cdc2..391eb91248 100644 --- a/tests/auto/quickcontrols/controls/data/tst_pageindicator.qml +++ b/tests/auto/quickcontrols/controls/data/tst_pageindicator.qml @@ -1,5 +1,5 @@ // Copyright (C) 2017 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only import QtQuick import QtTest @@ -15,23 +15,30 @@ TestCase { Component { id: pageIndicator - PageIndicator { } + PageIndicator { + objectName: "pageIndicator" + contentItem.objectName: "pageIndicatorContentItem" + } } Component { id: mouseArea - MouseArea { } + MouseArea { + objectName: "mouseArea" + } } - function test_defaults() { + function init() { failOnWarning(/.?/) + } + function test_defaults() { let control = createTemporaryObject(pageIndicator, testCase) verify(control) } function test_count() { - var control = createTemporaryObject(pageIndicator, testCase) + let control = createTemporaryObject(pageIndicator, testCase) verify(control) compare(control.count, 0) @@ -40,7 +47,7 @@ TestCase { } function test_currentIndex() { - var control = createTemporaryObject(pageIndicator, testCase) + let control = createTemporaryObject(pageIndicator, testCase) verify(control) compare(control.currentIndex, 0) @@ -56,13 +63,13 @@ TestCase { } function test_interactive(data) { - var control = createTemporaryObject(pageIndicator, testCase, {count: 5, spacing: 10, topPadding: 10, leftPadding: 10, rightPadding: 10, bottomPadding: 10}) + let control = createTemporaryObject(pageIndicator, testCase, {count: 5, spacing: 10, topPadding: 10, leftPadding: 10, rightPadding: 10, bottomPadding: 10}) verify(control) verify(!control.interactive) compare(control.currentIndex, 0) - var touch = touchEvent(control) + let touch = touchEvent(control) if (data.touch) touch.press(0, control).commit().release(0, control).commit() @@ -80,10 +87,10 @@ TestCase { compare(control.currentIndex, 2) // test also clicking outside delegates => the nearest should be selected - for (var i = 0; i < control.count; ++i) { - var child = control.contentItem.children[i] + for (let i = 0; i < control.count; ++i) { + let child = control.contentItem.children[i] - var points = [ + let points = [ Qt.point(child.width / 2, -2), // top Qt.point(-2, child.height / 2), // left Qt.point(child.width + 2, child.height / 2), // right @@ -95,12 +102,12 @@ TestCase { Qt.point(child.width + 2, child.height + 2), // bottom-right ] - for (var j = 0; j < points.length; ++j) { + for (let j = 0; j < points.length; ++j) { control.currentIndex = -1 compare(control.currentIndex, -1) - var point = points[j] - var pos = control.mapFromItem(child, x, y) + let point = points[j] + let pos = control.mapFromItem(child, x, y) if (data.touch) touch.press(0, control, pos.x, pos.y).commit().release(0, control, pos.x, pos.y).commit() else @@ -119,10 +126,10 @@ TestCase { // QTBUG-61785 function test_mouseArea(data) { - var ma = createTemporaryObject(mouseArea, testCase, {width: testCase.width, height: testCase.height}) + let ma = createTemporaryObject(mouseArea, testCase, {width: testCase.width, height: testCase.height}) verify(ma) - var control = pageIndicator.createObject(ma, {count: 5, interactive: data.interactive, width: testCase.width, height: testCase.height}) + let control = pageIndicator.createObject(ma, {count: 5, interactive: data.interactive, width: testCase.width, height: testCase.height}) verify(control) compare(control.interactive, data.interactive) @@ -133,7 +140,7 @@ TestCase { mouseRelease(control) verify(!ma.pressed) - var touch = touchEvent(control) + let touch = touchEvent(control) touch.press(0, control).commit() compare(ma.pressed, !data.interactive) diff --git a/tests/auto/quickcontrols/controls/data/tst_pane.qml b/tests/auto/quickcontrols/controls/data/tst_pane.qml index f823031c79..ab042edec2 100644 --- a/tests/auto/quickcontrols/controls/data/tst_pane.qml +++ b/tests/auto/quickcontrols/controls/data/tst_pane.qml @@ -1,9 +1,10 @@ // Copyright (C) 2017 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only import QtQuick import QtTest import QtQuick.Controls +import QtQuick.Layouts TestCase { id: testCase @@ -18,57 +19,22 @@ TestCase { Pane { } } - Component { - id: oneChildPane - Pane { - Item { - implicitWidth: 100 - implicitHeight: 30 - } - } - } - - Component { - id: twoChildrenPane - Pane { - Item { - implicitWidth: 100 - implicitHeight: 30 - } - Item { - implicitWidth: 200 - implicitHeight: 60 - } - } + function init() { + failOnWarning(/.?/) } - Component { - id: contentPane - Pane { - contentItem: Item { - implicitWidth: 100 - implicitHeight: 30 - } - } - } + function test_implicitContentItem() { + let control = createTemporaryObject(pane, testCase, {width: 100, height: 100}) + verify(control) - Component { - id: pressPane - MouseArea { - width: 200 - height: 200 - property int pressCount - onPressed: ++pressCount - Pane { - anchors.fill: parent - } - } + compare(control.width, 100) + compare(control.height, 100) + compare(control.contentItem.width, control.availableWidth) + compare(control.contentItem.height, control.availableHeight) } function test_empty() { - failOnWarning(/.?/) - - var control = createTemporaryObject(pane, testCase) + let control = createTemporaryObject(pane, testCase) verify(control) verify(control.contentItem) @@ -78,8 +44,18 @@ TestCase { compare(control.implicitContentHeight, 0) } + Component { + id: oneChildPane + Pane { + Item { + implicitWidth: 100 + implicitHeight: 30 + } + } + } + function test_oneChild() { - var control = createTemporaryObject(oneChildPane, testCase) + let control = createTemporaryObject(oneChildPane, testCase) verify(control) compare(control.contentWidth, 100) @@ -101,8 +77,22 @@ TestCase { verify(control.implicitHeight > 40) } + Component { + id: twoChildrenPane + Pane { + Item { + implicitWidth: 100 + implicitHeight: 30 + } + Item { + implicitWidth: 200 + implicitHeight: 60 + } + } + } + function test_twoChildren() { - var control = createTemporaryObject(twoChildrenPane, testCase) + let control = createTemporaryObject(twoChildrenPane, testCase) verify(control) compare(control.contentWidth, 0) @@ -113,8 +103,18 @@ TestCase { verify(control.implicitHeight > 0) } + Component { + id: contentPane + Pane { + contentItem: Item { + implicitWidth: 100 + implicitHeight: 30 + } + } + } + function test_contentItem() { - var control = createTemporaryObject(contentPane, testCase) + let control = createTemporaryObject(contentPane, testCase) verify(control) compare(control.contentWidth, 100) @@ -125,18 +125,47 @@ TestCase { verify(control.implicitHeight > 30) } - function test_implicitContentItem() { - var control = createTemporaryObject(pane, testCase, {width: 100, height: 100}) + Component { + id: contentItemPane + Pane { + property string description: "" + contentItem: ColumnLayout { + Label { + Layout.maximumWidth: 100 + text: description + elide: Label.ElideRight + } + } + Component.onCompleted: { + description = "Binding loop issue ".repeat(100) + } + } + } + + function test_paneBindingLoop() { + let control = createTemporaryObject(contentItemPane, testCase) verify(control) + // Wait for content item to be polished + waitForPolish(control.contentItem) - compare(control.width, 100) - compare(control.height, 100) - compare(control.contentItem.width, control.availableWidth) - compare(control.contentItem.height, control.availableHeight) + compare(control.contentWidth, 100) + } + + Component { + id: pressPane + MouseArea { + width: 200 + height: 200 + property int pressCount + onPressed: ++pressCount + Pane { + anchors.fill: parent + } + } } function test_press() { - var control = createTemporaryObject(pressPane, testCase) + let control = createTemporaryObject(pressPane, testCase) verify(control) compare(control.pressCount, 0) diff --git a/tests/auto/quickcontrols/controls/data/tst_popup.qml b/tests/auto/quickcontrols/controls/data/tst_popup.qml index 23879d817a..2428192961 100644 --- a/tests/auto/quickcontrols/controls/data/tst_popup.qml +++ b/tests/auto/quickcontrols/controls/data/tst_popup.qml @@ -1,9 +1,10 @@ // Copyright (C) 2017 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only import QtQuick import QtTest import QtQuick.Controls +import QtQuick.Layouts import QtQuick.Templates as T import QtQuick.NativeStyle as NativeStyle import Qt.test.controls @@ -42,37 +43,39 @@ TestCase { SignalSpy { } } - function test_defaults() { + function init() { failOnWarning(/.?/) + } + function test_defaults() { let control = createTemporaryObject(popupControl, testCase) verify(control) } function test_padding() { - var control = createTemporaryObject(popupTemplate, testCase) + let control = createTemporaryObject(popupTemplate, testCase) verify(control) - var paddingSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "paddingChanged"}) + let paddingSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "paddingChanged"}) verify(paddingSpy.valid) - var topPaddingSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "topPaddingChanged"}) + let topPaddingSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "topPaddingChanged"}) verify(topPaddingSpy.valid) - var leftPaddingSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "leftPaddingChanged"}) + let leftPaddingSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "leftPaddingChanged"}) verify(leftPaddingSpy.valid) - var rightPaddingSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "rightPaddingChanged"}) + let rightPaddingSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "rightPaddingChanged"}) verify(rightPaddingSpy.valid) - var bottomPaddingSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "bottomPaddingChanged"}) + let bottomPaddingSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "bottomPaddingChanged"}) verify(bottomPaddingSpy.valid) - var paddingChanges = 0 - var topPaddingChanges = 0 - var leftPaddingChanges = 0 - var rightPaddingChanges = 0 - var bottomPaddingChanges = 0 + let paddingChanges = 0 + let topPaddingChanges = 0 + let leftPaddingChanges = 0 + let rightPaddingChanges = 0 + let bottomPaddingChanges = 0 compare(control.padding, 0) compare(control.topPadding, 0) @@ -159,17 +162,17 @@ TestCase { } function test_availableSize() { - var control = createTemporaryObject(popupTemplate, testCase) + let control = createTemporaryObject(popupTemplate, testCase) verify(control) - var availableWidthSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "availableWidthChanged"}) + let availableWidthSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "availableWidthChanged"}) verify(availableWidthSpy.valid) - var availableHeightSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "availableHeightChanged"}) + let availableHeightSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "availableHeightChanged"}) verify(availableHeightSpy.valid) - var availableWidthChanges = 0 - var availableHeightChanges = 0 + let availableWidthChanges = 0 + let availableHeightChanges = 0 control.width = 100 compare(control.availableWidth, 100) @@ -229,14 +232,14 @@ TestCase { } function test_position() { - var control = createTemporaryObject(popupControl, testCase, {visible: true, leftMargin: 10, topMargin: 20, width: 100, height: 100}) + let control = createTemporaryObject(popupControl, testCase, {visible: true, leftMargin: 10, topMargin: 20, width: 100, height: 100}) verify(control) verify(control.visible) - var xSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "xChanged"}) + let xSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "xChanged"}) verify(xSpy.valid) - var ySpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "yChanged"}) + let ySpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "yChanged"}) verify(ySpy.valid) // moving outside margins does not trigger change notifiers @@ -285,7 +288,7 @@ TestCase { } function test_resetSize() { - var control = createTemporaryObject(popupControl, testCase, {visible: true, margins: 0}) + let control = createTemporaryObject(popupControl, testCase, {visible: true, margins: 0}) verify(control) control.scale = 1.0 @@ -302,7 +305,7 @@ TestCase { } function test_negativeMargins() { - var control = createTemporaryObject(popupControl, testCase, {implicitWidth: testCase.width, implicitHeight: testCase.height}) + let control = createTemporaryObject(popupControl, testCase, {implicitWidth: testCase.width, implicitHeight: testCase.height}) verify(control) control.open() @@ -319,12 +322,12 @@ TestCase { control.x = -10 control.y = -10 - compare(control.x, 0) - compare(control.y, 0) + compare(control.x, -10) + compare(control.y, -10) } function test_margins() { - var control = createTemporaryObject(popupTemplate, testCase, {width: 100, height: 100}) + let control = createTemporaryObject(popupTemplate, testCase, {width: 100, height: 100}) verify(control) control.open() @@ -410,7 +413,7 @@ TestCase { } function test_background() { - var control = createTemporaryObject(popupTemplate, testCase) + let control = createTemporaryObject(popupTemplate, testCase) verify(control) control.background = rect.createObject(testCase) @@ -455,8 +458,8 @@ TestCase { } function getChild(control, objname, idx) { - var index = idx - for (var i = index+1; i < control.children.length; i++) + let index = idx + for (let i = index+1; i < control.children.length; i++) { if (control.children[i].objectName === objname) { index = i @@ -525,15 +528,15 @@ TestCase { } function test_font() { // QTBUG_50984, QTBUG-51696 - var window = createTemporaryObject(component, testCase) + let window = createTemporaryObject(component, testCase) verify(window) compare(window.font.pixelSize, 40) compare(window.pane.font.pixelSize, 30) compare(window.pane.button.font.pixelSize, 20) compare(window.popup.font.pixelSize, 40) - var idx1 = getChild(window.popup.listview.contentItem, "delegate", -1) - var idx2 = getChild(window.popup.listview.contentItem, "delegate", idx1) + let idx1 = getChild(window.popup.listview.contentItem, "delegate", -1) + let idx2 = getChild(window.popup.listview.contentItem, "delegate", idx1) window.popup.listview.contentItem.children[idx1].fontspy.clear() window.popup.listview.contentItem.children[idx2].fontspy.clear() window.popup.button.fontspy.clear() @@ -649,7 +652,7 @@ TestCase { function test_locale() { // QTBUG_50984 // test looking up natural locale from ancestors - var control = createTemporaryObject(localeComponent, applicationWindow.contentItem) + let control = createTemporaryObject(localeComponent, applicationWindow.contentItem) verify(control) compare(control.locale.name, "en_US") @@ -732,10 +735,10 @@ TestCase { function test_locale_changes() { // QTBUG_50984 // test default locale and locale inheritance - var control = createTemporaryObject(localeChangeComponent, applicationWindow.contentItem) + let control = createTemporaryObject(localeChangeComponent, applicationWindow.contentItem) verify(control) - var defaultLocale = Qt.locale() + let defaultLocale = Qt.locale() compare(control.ApplicationWindow.window.locale.name, defaultLocale.name) compare(control.locale.name, defaultLocale.name) compare(control.button.locale.name, defaultLocale.name) @@ -901,10 +904,10 @@ TestCase { } function test_size() { - var control = createTemporaryObject(popupControl, testCase) + let control = createTemporaryObject(popupControl, testCase) verify(control) - var openedSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "opened"}) + let openedSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "opened"}) verify(openedSpy.valid) control.open() @@ -962,7 +965,7 @@ TestCase { } function test_visible() { - var control = createTemporaryObject(popupTemplate, testCase, {visible: true}) + let control = createTemporaryObject(popupTemplate, testCase, {visible: true}) verify(control) // QTBUG-51989 @@ -1020,7 +1023,7 @@ TestCase { } function indexOf(array, item) { - for (var idx = 0; idx < array.length; ++idx) { + for (let idx = 0; idx < array.length; ++idx) { if (item === array[idx]) return idx; } @@ -1028,13 +1031,13 @@ TestCase { } function findOverlay(window, popup) { - var item = popup.contentItem.parent - var idx = indexOf(window.Overlay.overlay.children, item) + let item = popup.contentItem.parent + let idx = indexOf(window.Overlay.overlay.children, item) return window.Overlay.overlay.children[idx - 1] } function test_overlay() { - var window = createTemporaryObject(overlayTest, testCase) + let window = createTemporaryObject(overlayTest, testCase) verify(window) window.requestActivate() @@ -1042,7 +1045,7 @@ TestCase { compare(window.Overlay.overlay.children.length, 0) - var firstOverlay = findOverlay(window, window.firstDrawer) + let firstOverlay = findOverlay(window, window.firstDrawer) verify(!firstOverlay) window.firstDrawer.open() compare(window.Overlay.overlay.children.length, 2) // 1 drawer + 1 overlay @@ -1053,7 +1056,7 @@ TestCase { indexOf(window.Overlay.overlay.children, window.firstDrawer.contentItem.parent) - 1) tryCompare(firstOverlay, "opacity", 1.0) - var secondOverlay = findOverlay(window, window.secondDrawer) + let secondOverlay = findOverlay(window, window.secondDrawer) verify(!secondOverlay) window.secondDrawer.open() compare(window.Overlay.overlay.children.length, 4) // 2 drawers + 2 overlays @@ -1076,7 +1079,7 @@ TestCase { verify(!secondOverlay) compare(window.Overlay.overlay.children.length, 0) - var modalOverlay = findOverlay(window, window.modalPopup) + let modalOverlay = findOverlay(window, window.modalPopup) verify(!modalOverlay) window.modalPopup.open() modalOverlay = findOverlay(window, window.modalPopup) @@ -1086,7 +1089,7 @@ TestCase { tryCompare(modalOverlay, "opacity", 1.0) compare(window.Overlay.overlay.children.length, 2) // 1 popup + 1 overlay - var modelessOverlay = findOverlay(window, window.modelessPopup) + let modelessOverlay = findOverlay(window, window.modelessPopup) verify(!modelessOverlay) window.modelessPopup.open() modelessOverlay = findOverlay(window, window.modelessPopup) @@ -1135,10 +1138,10 @@ TestCase { } function test_attached_applicationwindow() { - var control = createTemporaryObject(popupControl, applicationWindow.contentItem) + let control = createTemporaryObject(popupControl, applicationWindow.contentItem) verify(control) - var child = rect.createObject(control.contentItem) + let child = rect.createObject(control.contentItem) compare(control.ApplicationWindow.window, applicationWindow) compare(control.contentItem.ApplicationWindow.window, applicationWindow) @@ -1159,14 +1162,14 @@ TestCase { } function test_openedClosed() { - var control = createTemporaryObject(pausePopup, testCase) + let control = createTemporaryObject(pausePopup, testCase) verify(control) - var openedSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "opened"}) + let openedSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "opened"}) verify(openedSpy.valid) - var closedSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "closed"}) + let closedSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "closed"}) verify(closedSpy.valid) - var openedChangeSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "openedChanged"}) + let openedChangeSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "openedChanged"}) verify(openedChangeSpy.valid) control.open() @@ -1214,15 +1217,15 @@ TestCase { } function test_xyBindingLoop() { - var window = createTemporaryObject(xyBindingLoop, testCase) - var control = window.popup + let window = createTemporaryObject(xyBindingLoop, testCase) + let control = window.popup waitForRendering(control.contentItem) compare(control.x, (control.parent.width - control.width) / 2) compare(control.y, (control.parent.height - control.height) / 2) } function test_windowParent() { - var control = createTemporaryObject(popupControl, applicationWindow, {width: 100, height: 100}) + let control = createTemporaryObject(popupControl, applicationWindow, {width: 100, height: 100}) verify(control) control.open() @@ -1230,7 +1233,7 @@ TestCase { } function test_deferredBackgroundSize() { - var control = createTemporaryObject(popupControl, testCase, {width: 200, height: 100}) + let control = createTemporaryObject(popupControl, testCase, {width: 200, height: 100}) verify(control) compare(control.background.width, 200 + (control.background.leftInset || 0) + (control.background.rightInset || 0)) @@ -1238,8 +1241,12 @@ TestCase { } function test_anchors() { - var control = createTemporaryObject(popupControl, applicationWindow.contentItem.Overlay.overlay, + let control = createTemporaryObject(popupControl, applicationWindow.contentItem.Overlay.overlay, { visible: true, width: 100, height: 100 }) + + applicationWindow.visible = true + verify(waitForRendering(applicationWindow.contentItem)) + verify(control) verify(control.visible) // If there is a transition then make sure it is finished @@ -1249,14 +1256,12 @@ TestCase { compare(control.x, 0) compare(control.y, 0) - var overlay = control.Overlay.overlay + let overlay = control.Overlay.overlay verify(overlay) - var centerInSpy = createTemporaryObject(signalSpy, testCase, { target: control.anchors, signalName: "centerInChanged" }) + let centerInSpy = createTemporaryObject(signalSpy, testCase, { target: control.anchors, signalName: "centerInChanged" }) verify(centerInSpy.valid) - applicationWindow.visible = true - verify(waitForRendering(applicationWindow.contentItem)) verify(overlay.width > 0) verify(overlay.height > 0) @@ -1267,7 +1272,7 @@ TestCase { compare(control.y, (overlay.height - (control.width * control.scale)) / 2) // Ensure that it warns when trying to set it to an item that's not its parent. - var anotherItem = createTemporaryObject(rect, applicationWindow.contentItem, { x: 100, y: 100, width: 50, height: 50 }) + let anotherItem = createTemporaryObject(rect, applicationWindow.contentItem, { x: 100, y: 100, width: 50, height: 50 }) verify(anotherItem) ignoreWarning(new RegExp(".*QML Popup: Popup can only be centered within its immediate parent or Overlay.overlay")) @@ -1338,13 +1343,13 @@ TestCase { function test_shortcut() { // Tests that a Shortcut with Qt.WindowShortcut context // that is declared within a Popup is activated. - var window = createTemporaryObject(shortcutWindowComponent, testCase) - var control = window.popup + let window = createTemporaryObject(shortcutWindowComponent, testCase) + let control = window.popup window.requestActivate() tryCompare(window, "active", true) - var shortcutActivatedSpy = createTemporaryObject(signalSpy, testCase, + let shortcutActivatedSpy = createTemporaryObject(signalSpy, testCase, { target: window.shortcut, signalName: "activated"} ) verify(shortcutActivatedSpy.valid) @@ -1430,6 +1435,8 @@ TestCase { let popup = window.popup popup.open() + tryCompare(popup, "opened", true) + waitForRendering(popup.contentItem) // mouse clicks into the popup must not propagate to the parent mouseClick(window) @@ -1449,6 +1456,18 @@ TestCase { mouseRelease(title, pressPoint.x, pressPoint.y) compare(title.pressedPosition, Qt.point(0, 0)) + + // Set modal as true and check for the same operation + popup.modal = true + oldPos = Qt.point(popup.x, popup.y) + mousePress(title, pressPoint.x, pressPoint.y) + fuzzyCompare(title.pressedPosition.x, pressPoint.x, 1) + fuzzyCompare(title.pressedPosition.y, pressPoint.y, 1) + mouseMove(title, pressPoint.x + 5, pressPoint.y + 5) + fuzzyCompare(popup.x, oldPos.x + 5, 1) + fuzzyCompare(popup.y, oldPos.y + 5, 1) + mouseRelease(title, pressPoint.x, pressPoint.y) + compare(title.pressedPosition, Qt.point(0, 0)) } Component { @@ -1470,4 +1489,73 @@ TestCase { let rect = findChild(control.Overlay.overlay, "rect") verify(rect) } + + Component { + id: popupOverlay + + Popup { + id: popupCenterIn + property alias text: toastText.text + anchors.centerIn: Overlay.overlay + dim: true + modal: true + contentItem: ColumnLayout { + Text { + id: toastText + Layout.fillWidth: true + wrapMode: Text.Wrap + } + } + } + } + + function test_popupOverlayCenterIn() { + let control = createTemporaryObject(popupOverlay, testCase) + verify(control) + + // Modify text in the popup content item + control.text = "this is a long text causing a line break to show the binding loop " + + "(height) again after the first initialization of the text"; + + // Open popup item and wait for it to be rendered + control.open() + waitForRendering(testCase) + tryCompare(control, "opened", true) + + // Verify popup position + compare(control.x, 0) + compare(control.y, control.parent.height / 2 - control.height / 2) + control.close() + } + + Component { + id: popupWithOverlayInLoader + + Loader { + id: loader + active: false + sourceComponent: Item { + anchors.fill: parent + Popup { + modal: true + visible: true + Overlay.modal: Rectangle { color: 'grey' } + } + } + } + } + + function test_popupWithOverlayInLoader() { // QTBUG-122915 + let loader = createTemporaryObject(popupWithOverlayInLoader, testCase) + verify(loader) + + let overlay = loader.Overlay.overlay + verify(overlay) + + loader.active = true + tryCompare(overlay, "visible", true) + + loader.active = false + tryCompare(overlay, "visible", false) + } } diff --git a/tests/auto/quickcontrols/controls/data/tst_progressbar.qml b/tests/auto/quickcontrols/controls/data/tst_progressbar.qml index 6484df815a..043863043d 100644 --- a/tests/auto/quickcontrols/controls/data/tst_progressbar.qml +++ b/tests/auto/quickcontrols/controls/data/tst_progressbar.qml @@ -1,5 +1,5 @@ // Copyright (C) 2017 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only import QtQuick import QtTest @@ -18,15 +18,17 @@ TestCase { ProgressBar { } } - function test_defaults() { + function init() { failOnWarning(/.?/) + } + function test_defaults() { let control = createTemporaryObject(progressBar, testCase) verify(control) } function test_value() { - var control = createTemporaryObject(progressBar, testCase) + let control = createTemporaryObject(progressBar, testCase) verify(control) compare(control.value, 0.0) @@ -41,7 +43,7 @@ TestCase { } function test_range() { - var control = createTemporaryObject(progressBar, testCase, {from: 0, to: 100, value: 50}) + let control = createTemporaryObject(progressBar, testCase, {from: 0, to: 100, value: 50}) verify(control) compare(control.from, 0) @@ -73,7 +75,7 @@ TestCase { } function test_inverted() { - var control = createTemporaryObject(progressBar, testCase, {from: 1.0, to: -1.0}) + let control = createTemporaryObject(progressBar, testCase, {from: 1.0, to: -1.0}) verify(control) compare(control.from, 1.0) @@ -95,7 +97,7 @@ TestCase { } function test_position() { - var control = createTemporaryObject(progressBar, testCase) + let control = createTemporaryObject(progressBar, testCase) verify(control) compare(control.value, 0) @@ -111,7 +113,7 @@ TestCase { } function test_visualPosition() { - var control = createTemporaryObject(progressBar, testCase) + let control = createTemporaryObject(progressBar, testCase) verify(control) compare(control.value, 0) @@ -143,7 +145,7 @@ TestCase { } function test_indeterminate() { - var control = createTemporaryObject(progressBar, testCase) + let control = createTemporaryObject(progressBar, testCase) verify(control) compare(control.indeterminate, false) diff --git a/tests/auto/quickcontrols/controls/data/tst_radiobutton.qml b/tests/auto/quickcontrols/controls/data/tst_radiobutton.qml index 08caac977d..a4d0a08d7d 100644 --- a/tests/auto/quickcontrols/controls/data/tst_radiobutton.qml +++ b/tests/auto/quickcontrols/controls/data/tst_radiobutton.qml @@ -1,5 +1,5 @@ // Copyright (C) 2017 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only import QtQuick import QtTest @@ -25,15 +25,17 @@ TestCase { } } - function test_defaults() { + function init() { failOnWarning(/.?/) + } + function test_defaults() { let control = createTemporaryObject(radioButton, testCase) verify(control) } function test_text() { - var control = createTemporaryObject(radioButton, testCase) + let control = createTemporaryObject(radioButton, testCase) verify(control) compare(control.text, "") @@ -44,10 +46,10 @@ TestCase { } function test_checked() { - var control = createTemporaryObject(radioButton, testCase) + let control = createTemporaryObject(radioButton, testCase) verify(control) - var sequenceSpy = signalSequenceSpy.createObject(control, {target: control}) + let sequenceSpy = signalSequenceSpy.createObject(control, {target: control}) sequenceSpy.expectedSequence = [] // No change expected compare(control.checked, false) @@ -65,10 +67,10 @@ TestCase { } function test_mouse() { - var control = createTemporaryObject(radioButton, testCase) + let control = createTemporaryObject(radioButton, testCase) verify(control) - var sequenceSpy = signalSequenceSpy.createObject(control, {target: control}) + let sequenceSpy = signalSequenceSpy.createObject(control, {target: control}) // check sequenceSpy.expectedSequence = [["pressedChanged", { "pressed": true, "checked": false }], @@ -127,12 +129,12 @@ TestCase { } function test_touch() { - var control = createTemporaryObject(radioButton, testCase) + let control = createTemporaryObject(radioButton, testCase) verify(control) - var touch = touchEvent(control) + let touch = touchEvent(control) - var sequenceSpy = signalSequenceSpy.createObject(control, {target: control}) + let sequenceSpy = signalSequenceSpy.createObject(control, {target: control}) // check sequenceSpy.expectedSequence = [["pressedChanged", { "pressed": true, "checked": false }], @@ -184,10 +186,10 @@ TestCase { } function test_keys() { - var control = createTemporaryObject(radioButton, testCase) + let control = createTemporaryObject(radioButton, testCase) verify(control) - var sequenceSpy = signalSequenceSpy.createObject(control, {target: control}) + let sequenceSpy = signalSequenceSpy.createObject(control, {target: control}) sequenceSpy.expectedSequence = [] control.forceActiveFocus() @@ -220,8 +222,8 @@ TestCase { sequenceSpy.expectedSequence = [] // Not testing Key_Enter and Key_Return because QGnomeTheme uses them for // pressing buttons and the CI uses the QGnomeTheme platform theme. - var keys = [Qt.Key_Escape, Qt.Key_Tab] - for (var i = 0; i < keys.length; ++i) { + let keys = [Qt.Key_Escape, Qt.Key_Tab] + for (let i = 0; i < keys.length; ++i) { sequenceSpy.reset() keyClick(keys[i]) compare(control.checked, true) @@ -238,7 +240,7 @@ TestCase { } function test_binding() { - var container = createTemporaryObject(twoRadioButtons, testCase) + let container = createTemporaryObject(twoRadioButtons, testCase) verify(container) compare(container.rb1.checked, false) @@ -277,65 +279,65 @@ TestCase { } function test_autoExclusive() { - var container = createTemporaryObject(radioButtonGroup, testCase) + let container = createTemporaryObject(radioButtonGroup, testCase) compare(container.children.length, 8) - var checkStates = [false, false, false, false, false, false, false, false] - for (var i = 0; i < 8; ++i) + let checkStates = [false, false, false, false, false, false, false, false] + for (let i = 0; i < 8; ++i) compare(container.children[i].checked, checkStates[i]) container.children[0].checked = true checkStates[0] = true - for (i = 0; i < 8; ++i) + for (let i = 0; i < 8; ++i) compare(container.children[i].checked, checkStates[i]) container.children[1].checked = true checkStates[0] = false checkStates[1] = true - for (i = 0; i < 8; ++i) + for (let i = 0; i < 8; ++i) compare(container.children[i].checked, checkStates[i]) container.children[2].checked = true checkStates[2] = true - for (i = 0; i < 8; ++i) + for (let i = 0; i < 8; ++i) compare(container.children[i].checked, checkStates[i]) container.children[3].checked = true checkStates[2] = false checkStates[3] = true - for (i = 0; i < 8; ++i) + for (let i = 0; i < 8; ++i) compare(container.children[i].checked, checkStates[i]) container.children[4].checked = true checkStates[4] = true - for (i = 0; i < 8; ++i) + for (let i = 0; i < 8; ++i) compare(container.children[i].checked, checkStates[i]) container.children[5].checked = true checkStates[4] = false checkStates[5] = true - for (i = 0; i < 8; ++i) + for (let i = 0; i < 8; ++i) compare(container.children[i].checked, checkStates[i]) container.children[6].checked = true checkStates[6] = true - for (i = 0; i < 8; ++i) + for (let i = 0; i < 8; ++i) compare(container.children[i].checked, checkStates[i]) container.children[7].checked = true checkStates[7] = true - for (i = 0; i < 8; ++i) + for (let i = 0; i < 8; ++i) compare(container.children[i].checked, checkStates[i]) container.children[0].checked = true checkStates[0] = true checkStates[1] = false - for (i = 0; i < 8; ++i) + for (let i = 0; i < 8; ++i) compare(container.children[i].checked, checkStates[i]) } function test_baseline() { - var control = createTemporaryObject(radioButton, testCase) + let control = createTemporaryObject(radioButton, testCase) verify(control) compare(control.baselineOffset, control.contentItem.y + control.contentItem.baselineOffset) } diff --git a/tests/auto/quickcontrols/controls/data/tst_radiodelegate.qml b/tests/auto/quickcontrols/controls/data/tst_radiodelegate.qml index fe89838bda..fc6d93886f 100644 --- a/tests/auto/quickcontrols/controls/data/tst_radiodelegate.qml +++ b/tests/auto/quickcontrols/controls/data/tst_radiodelegate.qml @@ -1,5 +1,5 @@ // Copyright (C) 2017 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only import QtQuick import QtTest @@ -20,16 +20,18 @@ TestCase { // TODO: data-fy tst_radiobutton (rename to tst_radio?) so we don't duplicate its tests here? - function test_defaults() { + function init() { failOnWarning(/.?/) + } - var control = createTemporaryObject(radioDelegate, testCase); + function test_defaults() { + let control = createTemporaryObject(radioDelegate, testCase); verify(control); verify(!control.checked); } function test_checked() { - var control = createTemporaryObject(radioDelegate, testCase); + let control = createTemporaryObject(radioDelegate, testCase); verify(control); mouseClick(control); @@ -40,17 +42,17 @@ TestCase { } function test_baseline() { - var control = createTemporaryObject(radioDelegate, testCase); + let control = createTemporaryObject(radioDelegate, testCase); verify(control); compare(control.baselineOffset, control.contentItem.y + control.contentItem.baselineOffset); } function test_spacing() { - var control = createTemporaryObject(radioDelegate, testCase, { text: "Some long, long, long text" }) + let control = createTemporaryObject(radioDelegate, testCase, { text: "Some long, long, long text" }) verify(control) verify(control.contentItem.implicitWidth + control.leftPadding + control.rightPadding > control.background.implicitWidth) - var textLabel = findChild(control.contentItem, "label") + let textLabel = findChild(control.contentItem, "label") verify(textLabel) // The implicitWidth of the IconLabel that all buttons use as their contentItem should be @@ -77,7 +79,7 @@ TestCase { } function test_display(data) { - var control = createTemporaryObject(radioDelegate, testCase, { + let control = createTemporaryObject(radioDelegate, testCase, { text: "RadioDelegate", display: data.display, width: 400, @@ -87,11 +89,11 @@ TestCase { verify(control) compare(control.icon.source, "qrc:/qt-project.org/imports/QtQuick/Controls/Basic/images/check.png") - var iconImage = findChild(control.contentItem, "image") - var textLabel = findChild(control.contentItem, "label") + let iconImage = findChild(control.contentItem, "image") + let textLabel = findChild(control.contentItem, "label") - var availableWidth = control.availableWidth - control.indicator.width - control.spacing - var indicatorOffset = control.mirrored ? control.indicator.width + control.spacing : 0 + let availableWidth = control.availableWidth - control.indicator.width - control.spacing + let indicatorOffset = control.mirrored ? control.indicator.width + control.spacing : 0 switch (control.display) { case RadioDelegate.IconOnly: diff --git a/tests/auto/quickcontrols/controls/data/tst_rangeslider.qml b/tests/auto/quickcontrols/controls/data/tst_rangeslider.qml index 91e366c819..a574566bfb 100644 --- a/tests/auto/quickcontrols/controls/data/tst_rangeslider.qml +++ b/tests/auto/quickcontrols/controls/data/tst_rangeslider.qml @@ -1,5 +1,5 @@ // Copyright (C) 2017 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only import QtQuick import QtTest @@ -42,10 +42,12 @@ TestCase { } } - function test_defaults() { + function init() { failOnWarning(/.?/) + } - var control = createTemporaryObject(sliderComponent, testCase) + function test_defaults() { + let control = createTemporaryObject(sliderComponent, testCase) verify(control) compare(control.stepSize, 0) @@ -56,7 +58,7 @@ TestCase { } function test_values() { - var control = createTemporaryObject(sliderComponent, testCase) + let control = createTemporaryObject(sliderComponent, testCase) verify(control) compare(control.first.value, 0.0) @@ -81,7 +83,7 @@ TestCase { } function test_range() { - var control = createTemporaryObject(sliderComponent, testCase, { from: 0, to: 100, "first.value": 50, "second.value": 100 }) + let control = createTemporaryObject(sliderComponent, testCase, { from: 0, to: 100, "first.value": 50, "second.value": 100 }) verify(control) compare(control.from, 0) @@ -115,16 +117,16 @@ TestCase { } function test_setToFromUpdatesHandles() { - var control = createTemporaryObject(sliderComponent, testCase, { from: 0, to: 100, "first.value": 50, "second.value": 75 }) + let control = createTemporaryObject(sliderComponent, testCase, { from: 0, to: 100, "first.value": 50, "second.value": 75 }) verify(control) let firstPos = control.first.position let secondPos = control.second.position - var firstPosChangesSpy = signalSpy.createObject(control, {target: control.first, signalName: "positionChanged"}) + let firstPosChangesSpy = signalSpy.createObject(control, {target: control.first, signalName: "positionChanged"}) verify(firstPosChangesSpy.valid) - var secondPosChangesSpy = signalSpy.createObject(control, {target: control.second, signalName: "positionChanged"}) + let secondPosChangesSpy = signalSpy.createObject(control, {target: control.second, signalName: "positionChanged"}) verify(secondPosChangesSpy.valid) // Increasing the 'to' value, so the positions of the handles should be @@ -152,7 +154,7 @@ TestCase { } function test_setValues() { - var control = createTemporaryObject(sliderComponent, testCase) + let control = createTemporaryObject(sliderComponent, testCase) verify(control) compare(control.from, 0) @@ -177,7 +179,7 @@ TestCase { } function test_inverted() { - var control = createTemporaryObject(sliderComponent, testCase, { from: 1.0, to: -1.0 }) + let control = createTemporaryObject(sliderComponent, testCase, { from: 1.0, to: -1.0 }) verify(control) compare(control.from, 1.0) @@ -207,7 +209,7 @@ TestCase { } function test_visualPosition() { - var control = createTemporaryObject(sliderComponent, testCase) + let control = createTemporaryObject(sliderComponent, testCase) verify(control) compare(control.first.value, 0.0) @@ -252,7 +254,7 @@ TestCase { } function test_orientation() { - var control = createTemporaryObject(sliderComponent, testCase) + let control = createTemporaryObject(sliderComponent, testCase) verify(control) compare(control.orientation, Qt.Horizontal) @@ -277,19 +279,19 @@ TestCase { } function test_mouse(data) { - var control = createTemporaryObject(sliderComponent, testCase, { orientation: data.orientation, live: data.live }) + let control = createTemporaryObject(sliderComponent, testCase, { orientation: data.orientation, live: data.live }) verify(control) - var firstPressedSpy = signalSpy.createObject(control, {target: control.first, signalName: "pressedChanged"}) + let firstPressedSpy = signalSpy.createObject(control, {target: control.first, signalName: "pressedChanged"}) verify(firstPressedSpy.valid) - var firstMovedSpy = signalSpy.createObject(control, {target: control.first, signalName: "moved"}) + let firstMovedSpy = signalSpy.createObject(control, {target: control.first, signalName: "moved"}) verify(firstMovedSpy.valid) - var secondPressedSpy = signalSpy.createObject(control, {target: control.second, signalName: "pressedChanged"}) + let secondPressedSpy = signalSpy.createObject(control, {target: control.second, signalName: "pressedChanged"}) verify(secondPressedSpy.valid) - var secondMovedSpy = signalSpy.createObject(control, {target: control.second, signalName: "moved"}) + let secondMovedSpy = signalSpy.createObject(control, {target: control.second, signalName: "moved"}) verify(secondMovedSpy.valid) // Press and release the first handle without moving it. @@ -380,9 +382,9 @@ TestCase { compare(control.second.value, 1.0) compare(control.second.position, 1.0) - var horizontal = control.orientation === Qt.Horizontal - var toX = horizontal ? control.width * 0.5 : control.first.handle.x - var toY = horizontal ? control.first.handle.y : control.height * 0.5 + let horizontal = control.orientation === Qt.Horizontal + let toX = horizontal ? control.width * 0.5 : control.first.handle.x + let toY = horizontal ? control.first.handle.y : control.height * 0.5 mouseMove(control, toX, toY) compare(firstPressedSpy.count, 5) compare(firstMovedSpy.count, 1) @@ -422,24 +424,25 @@ TestCase { } function test_touch(data) { - var control = createTemporaryObject(sliderComponent, testCase, { orientation: data.orientation, live: data.live }) + let control = createTemporaryObject(sliderComponent, testCase, { orientation: data.orientation, live: data.live }) verify(control) - var firstPressedSpy = signalSpy.createObject(control, {target: control.first, signalName: "pressedChanged"}) + let firstPressedSpy = signalSpy.createObject(control, {target: control.first, signalName: "pressedChanged"}) verify(firstPressedSpy.valid) - var firstMovedSpy = signalSpy.createObject(control, {target: control.first, signalName: "moved"}) + let firstMovedSpy = signalSpy.createObject(control, {target: control.first, signalName: "moved"}) verify(firstMovedSpy.valid) - var secondPressedSpy = signalSpy.createObject(control, {target: control.second, signalName: "pressedChanged"}) + let secondPressedSpy = signalSpy.createObject(control, {target: control.second, signalName: "pressedChanged"}) verify(secondPressedSpy.valid) - var secondMovedSpy = signalSpy.createObject(control, {target: control.second, signalName: "moved"}) + let secondMovedSpy = signalSpy.createObject(control, {target: control.second, signalName: "moved"}) verify(secondMovedSpy.valid) // Press and release the first handle without moving it. - var touch = touchEvent(control) - touch.press(0, control, control.width * 0.25, control.height * 0.75).commit() + let touch = touchEvent(control) + control.setValues(0, 1); + touch.press(0, control, control.leftPadding, control.height - control.bottomPadding - 1).commit() compare(firstPressedSpy.count, 1) compare(firstMovedSpy.count, 0) compare(secondPressedSpy.count, 0) @@ -451,7 +454,7 @@ TestCase { compare(control.second.value, 1.0) compare(control.second.position, 1.0) - touch.release(0, control, control.width * 0.25, control.height * 0.75).commit() + touch.release(0, control, control.leftPadding, control.height - control.bottomPadding - 1).commit() compare(firstPressedSpy.count, 2) compare(firstMovedSpy.count, 0) compare(secondPressedSpy.count, 0) @@ -464,7 +467,7 @@ TestCase { compare(control.second.position, 1.0) // Press and release the second handle without moving it. - touch.press(0, control, control.width * 0.75, control.height * 0.25).commit() + touch.press(0, control, control.width - control.rightPadding - 1, control.topPadding).commit() compare(firstPressedSpy.count, 2) compare(secondPressedSpy.count, 1) compare(control.first.pressed, false) @@ -474,7 +477,7 @@ TestCase { compare(control.second.value, 1.0) compare(control.second.position, 1.0) - touch.release(0, control, control.width * 0.75, control.height * 0.25).commit() + touch.release(0, control, control.width - control.rightPadding - 1, control.topPadding).commit() compare(firstPressedSpy.count, 2) compare(secondPressedSpy.count, 2) compare(control.first.pressed, false) @@ -516,9 +519,9 @@ TestCase { compare(control.second.position, 1.0) // Drag the first handle. - var horizontal = control.orientation === Qt.Horizontal - var toX = horizontal ? control.width * 0.5 : control.first.handle.x - var toY = horizontal ? control.first.handle.y : control.height * 0.5 + let horizontal = control.orientation === Qt.Horizontal + let toX = horizontal ? control.width * 0.5 : control.first.handle.x + let toY = horizontal ? control.first.handle.y : control.height * 0.5 touch.move(0, control, toX, toY).commit() compare(firstPressedSpy.count, 5) compare(secondPressedSpy.count, 2) @@ -545,11 +548,11 @@ TestCase { } function test_multiTouch() { - var control1 = createTemporaryObject(sliderComponent, testCase) + let control1 = createTemporaryObject(sliderComponent, testCase) verify(control1) // press and move the first handle of the first slider - var touch = touchEvent(control1) + let touch = touchEvent(control1) touch.press(0, control1, 0, 0).commit().move(0, control1, control1.width / 2, control1.height / 2).commit() compare(control1.first.pressed, true) compare(control1.first.position, 0.5) @@ -564,7 +567,7 @@ TestCase { compare(control1.second.pressed, true) compare(control1.second.position, 0.5) - var control2 = createTemporaryObject(sliderComponent, testCase, {y: control1.height}) + let control2 = createTemporaryObject(sliderComponent, testCase, {y: control1.height}) verify(control2) // press and move the first handle of the second slider @@ -604,7 +607,7 @@ TestCase { } function test_overlappingHandles() { - var control = createTemporaryObject(sliderComponent, testCase) + let control = createTemporaryObject(sliderComponent, testCase) verify(control) // By default, we force the second handle to be after the first in @@ -669,12 +672,12 @@ TestCase { } function test_keys(data) { - var control = createTemporaryObject(sliderComponent, testCase, { orientation: data.orientation }) + let control = createTemporaryObject(sliderComponent, testCase, { orientation: data.orientation }) verify(control) - var pressedCount = 0 + let pressedCount = 0 - var firstPressedSpy = signalSpy.createObject(control, {target: control.first, signalName: "pressedChanged"}) + let firstPressedSpy = signalSpy.createObject(control, {target: control.first, signalName: "pressedChanged"}) verify(firstPressedSpy.valid) control.first.handle.forceActiveFocus() @@ -682,7 +685,7 @@ TestCase { control.first.value = 0.5 - for (var d1 = 1; d1 <= 10; ++d1) { + for (let d1 = 1; d1 <= 10; ++d1) { keyPress(data.decrease) compare(control.first.pressed, true) compare(firstPressedSpy.count, ++pressedCount) @@ -695,7 +698,7 @@ TestCase { compare(firstPressedSpy.count, ++pressedCount) } - for (var i1 = 1; i1 <= 20; ++i1) { + for (let i1 = 1; i1 <= 20; ++i1) { keyPress(data.increase) compare(control.first.pressed, true) compare(firstPressedSpy.count, ++pressedCount) @@ -712,13 +715,13 @@ TestCase { control.stepSize = 0.25 pressedCount = 0; - var secondPressedSpy = signalSpy.createObject(control, {target: control.second, signalName: "pressedChanged"}) + let secondPressedSpy = signalSpy.createObject(control, {target: control.second, signalName: "pressedChanged"}) verify(secondPressedSpy.valid) control.second.handle.forceActiveFocus() verify(control.second.handle.activeFocus) - for (var d2 = 1; d2 <= 10; ++d2) { + for (let d2 = 1; d2 <= 10; ++d2) { keyPress(data.decrease) compare(control.second.pressed, true) compare(secondPressedSpy.count, ++pressedCount) @@ -731,7 +734,7 @@ TestCase { compare(secondPressedSpy.count, ++pressedCount) } - for (var i2 = 1; i2 <= 10; ++i2) { + for (let i2 = 1; i2 <= 10; ++i2) { keyPress(data.increase) compare(control.second.pressed, true) compare(secondPressedSpy.count, ++pressedCount) @@ -749,10 +752,10 @@ TestCase { // test with "unbalanced" paddings (left padding != right padding) to ensure // that the slider position calculation is done taking padding into account // ==> the position is _not_ 0.5 in the middle of the control - var control = createTemporaryObject(sliderComponent, testCase, { leftPadding: 10, rightPadding: 20, live: false }) + let control = createTemporaryObject(sliderComponent, testCase, { leftPadding: 10, rightPadding: 20, live: false }) verify(control) - var firstPressedSpy = signalSpy.createObject(control, {target: control.first, signalName: "pressedChanged"}) + let firstPressedSpy = signalSpy.createObject(control, {target: control.first, signalName: "pressedChanged"}) verify(firstPressedSpy.valid) mousePress(control, control.first.handle.x, control.first.handle.y, Qt.LeftButton) @@ -835,13 +838,13 @@ TestCase { } function test_snapMode_mouse(data) { - var control = createTemporaryObject(sliderComponent, testCase, {snapMode: data.snapMode, from: data.from, to: data.to, stepSize: 0.2, live: false, width: testCase.width}) + let control = createTemporaryObject(sliderComponent, testCase, {snapMode: data.snapMode, from: data.from, to: data.to, stepSize: 0.2, live: false, width: testCase.width}) verify(control) control.first.value = 0 control.second.value = data.to - var fuzz = 0.05 + let fuzz = 0.05 mousePress(control, control.leftPadding) compare(control.first.pressed, true) @@ -864,15 +867,15 @@ TestCase { } function test_snapMode_touch(data) { - var control = createTemporaryObject(sliderComponent, testCase, {snapMode: data.snapMode, from: data.from, to: data.to, stepSize: 0.2, live: false, width: testCase.width}) + let control = createTemporaryObject(sliderComponent, testCase, {snapMode: data.snapMode, from: data.from, to: data.to, stepSize: 0.2, live: false, width: testCase.width}) verify(control) control.first.value = 0 control.second.value = data.to - var fuzz = 0.05 + let fuzz = 0.05 - var touch = touchEvent(control) + let touch = touchEvent(control) touch.press(0, control, control.first.handle.x, control.first.handle.y).commit() compare(control.first.pressed, true) compare(control.first.value, data.values[0]) @@ -890,7 +893,7 @@ TestCase { } function test_focus() { - var control = createTemporaryObject(sliderComponent, testCase) + let control = createTemporaryObject(sliderComponent, testCase) verify(control) compare(control.activeFocus, false) @@ -930,10 +933,10 @@ TestCase { } function test_hover(data) { - var control = createTemporaryObject(sliderComponent, testCase, {hoverEnabled: data.hoverEnabled}) + let control = createTemporaryObject(sliderComponent, testCase, {hoverEnabled: data.hoverEnabled}) verify(control) - var node = control[data.node] + let node = control[data.node] compare(control.hovered, false) compare(node.hovered, false) @@ -946,7 +949,7 @@ TestCase { } function test_nullHandles() { - var control = createTemporaryObject(sliderComponent, testCase, {"second.value": 1}) + let control = createTemporaryObject(sliderComponent, testCase, {"second.value": 1}) verify(control) verify(control.first.handle) @@ -973,7 +976,7 @@ TestCase { } function test_touchDragThreshold_data() { - var d1 = 3; var d2 = 7; + let d1 = 3; let d2 = 7; return [ { tag: "horizontal", orientation: Qt.Horizontal, dx1: d1, dy1: 0, dx2: d2, dy2: 0 }, { tag: "vertical", orientation: Qt.Vertical, dx1: 0, dy1: -d1, dx2: 0, dy2: -d2 }, @@ -983,19 +986,19 @@ TestCase { } function test_touchDragThreshold(data) { - var control = createTemporaryObject(sliderComponent, testCase, {touchDragThreshold: 10, live: true, orientation: data.orientation, "first.value": 0, "second.value": 1}) + let control = createTemporaryObject(sliderComponent, testCase, {touchDragThreshold: 10, live: true, orientation: data.orientation, "first.value": 0, "second.value": 1}) verify(control) compare(control.touchDragThreshold, 10) - var valueChangedCount = 0 - var valueChangedSpy = signalSpy.createObject(control, {target: control, signalName: "touchDragThresholdChanged"}) + let valueChangedCount = 0 + let valueChangedSpy = signalSpy.createObject(control, {target: control, signalName: "touchDragThresholdChanged"}) verify(valueChangedSpy.valid) control.touchDragThreshold = undefined compare(control.touchDragThreshold, -1) // reset to -1 compare(valueChangedSpy.count, ++valueChangedCount) - var t = 5 + let t = 5 control.touchDragThreshold = t compare(control.touchDragThreshold, t) compare(valueChangedSpy.count, ++valueChangedCount) @@ -1004,26 +1007,26 @@ TestCase { compare(control.touchDragThreshold, t) compare(valueChangedSpy.count, valueChangedCount) - var pressedCount = 0 - var pressedCount2 = 0 - var visualPositionCount = 0 - var visualPositionCount2 = 0 + let pressedCount = 0 + let pressedCount2 = 0 + let visualPositionCount = 0 + let visualPositionCount2 = 0 - var pressedSpy = signalSpy.createObject(control, {target: control.first, signalName: "pressedChanged"}) + let pressedSpy = signalSpy.createObject(control, {target: control.first, signalName: "pressedChanged"}) verify(pressedSpy.valid) - var pressedSpy2 = signalSpy.createObject(control, {target: control.second, signalName: "pressedChanged"}) + let pressedSpy2 = signalSpy.createObject(control, {target: control.second, signalName: "pressedChanged"}) verify(pressedSpy2.valid) - var visualPositionSpy = signalSpy.createObject(control, {target: control.first, signalName: "visualPositionChanged"}) + let visualPositionSpy = signalSpy.createObject(control, {target: control.first, signalName: "visualPositionChanged"}) verify(visualPositionSpy.valid) - var visualPositionSpy2 = signalSpy.createObject(control, {target: control.second, signalName: "visualPositionChanged"}) + let visualPositionSpy2 = signalSpy.createObject(control, {target: control.second, signalName: "visualPositionChanged"}) verify(visualPositionSpy2.valid) - var touch = touchEvent(control) + let touch = touchEvent(control) control.first.value = 0.4 control.second.value = 1 - var x0 = control.first.handle.x + control.first.handle.width * 0.5 - var y0 = control.first.handle.y + control.first.handle.height * 0.5 + let x0 = control.first.handle.x + control.first.handle.width * 0.5 + let y0 = control.first.handle.y + control.first.handle.height * 0.5 touch.press(0, control, x0, y0).commit() compare(pressedSpy.count, ++pressedCount) compare(control.first.pressed, true) @@ -1073,7 +1076,7 @@ TestCase { } function test_valueAt(data) { - var control = createTemporaryObject(sliderComponent, testCase, data.properties) + let control = createTemporaryObject(sliderComponent, testCase, data.properties) verify(control) compare(control.valueAt(0.0), data.values[0]) @@ -1081,4 +1084,173 @@ TestCase { compare(control.valueAt(0.5), data.values[2]) compare(control.valueAt(1.0), data.values[3]) } + + function test_updatePositionOnPress() { + let control = createTemporaryObject(sliderComponent, testCase) + verify(control) + + let firstPressedSpy = signalSpy.createObject(control, {target: control.first, signalName: "pressedChanged"}) + verify(firstPressedSpy.valid) + + let firstMovedSpy = signalSpy.createObject(control, {target: control.first, signalName: "moved"}) + verify(firstMovedSpy.valid) + + let secondPressedSpy = signalSpy.createObject(control, {target: control.second, signalName: "pressedChanged"}) + verify(secondPressedSpy.valid) + + let secondMovedSpy = signalSpy.createObject(control, {target: control.second, signalName: "moved"}) + verify(secondMovedSpy.valid) + + // Touch press and release on the left corner + control.setValues(0.2, 0.8) + compare(control.first.value, 0.2) + compare(control.second.value, 0.8) + let touch = touchEvent(control) + touch.press(0, control, 0, control.height * 0.75).commit() + compare(firstPressedSpy.count, 1) + compare(firstMovedSpy.count, 0) + compare(secondPressedSpy.count, 0) + compare(secondMovedSpy.count, 0) + compare(control.first.pressed, true) + compare(control.first.value, 0.2) + compare(control.first.position, 0.2) + compare(control.second.pressed, false) + compare(control.second.value, 0.8) + compare(control.second.position, 0.8) + + touch.release(0, control, 0, control.height * 0.75).commit() + compare(firstPressedSpy.count, 2) + compare(firstMovedSpy.count, 1) + compare(secondPressedSpy.count, 0) + compare(secondMovedSpy.count, 0) + compare(control.first.pressed, false) + compare(control.first.value, 0.0) + compare(control.first.position, 0.0) + compare(control.second.pressed, false) + compare(control.second.value, 0.8) + compare(control.second.position, 0.8) + + firstPressedSpy.clear() + firstMovedSpy.clear() + secondPressedSpy.clear() + secondMovedSpy.clear() + + // Touch press and release on the right corner + // On touch, the handle position is updated on release + control.setValues(0.2, 0.8) + compare(control.first.value, 0.2) + compare(control.second.value, 0.8) + touch = touchEvent(control) + touch.press(0, control, control.width - control.rightPadding - 1, control.height * 0.75).commit() + compare(secondPressedSpy.count, 1) + compare(secondMovedSpy.count, 0) + compare(firstPressedSpy.count, 0) + compare(firstMovedSpy.count, 0) + compare(control.second.pressed, true) + compare(control.second.value, 0.8) + compare(control.second.position, 0.8) + compare(control.first.pressed, false) + compare(control.first.value, 0.2) + compare(control.first.position, 0.2) + + touch.release(0, control, control.width - control.rightPadding - 1, control.height * 0.75).commit() + compare(secondPressedSpy.count, 2) + compare(secondMovedSpy.count, 1) + compare(firstPressedSpy.count, 0) + compare(firstMovedSpy.count, 0) + compare(control.second.pressed, false) + compare(control.second.value, 1.0) + compare(control.second.position, 1.0) + compare(control.first.pressed, false) + compare(control.first.value, 0.2) + compare(control.first.position, 0.2) + + firstPressedSpy.clear() + firstMovedSpy.clear() + secondPressedSpy.clear() + secondMovedSpy.clear() + + // Mouse press and release on the left corner + // On mouse, the position is immediately updated on press + control.setValues(0.2, 0.8) + compare(control.first.value, 0.2) + compare(control.second.value, 0.8) + mousePress(control, 0, control.height * 0.75, Qt.LeftButton) + compare(firstPressedSpy.count, 1) + compare(firstMovedSpy.count, 1) + compare(secondPressedSpy.count, 0) + compare(secondMovedSpy.count, 0) + compare(control.first.pressed, true) + compare(control.first.value, 0.0) + compare(control.first.position, 0.0) + compare(control.second.pressed, false) + compare(control.second.value, 0.8) + compare(control.second.position, 0.8) + + mouseRelease(control, 0, control.height * 0.75, Qt.LeftButton) + compare(firstPressedSpy.count, 2) + compare(firstMovedSpy.count, 1) + compare(secondPressedSpy.count, 0) + compare(secondMovedSpy.count, 0) + compare(control.first.pressed, false) + compare(control.first.value, 0.0) + compare(control.first.position, 0.0) + compare(control.second.pressed, false) + compare(control.second.value, 0.8) + compare(control.second.position, 0.8) + + firstPressedSpy.clear() + firstMovedSpy.clear() + secondPressedSpy.clear() + secondMovedSpy.clear() + + // Mouse press and release on the right corner + control.setValues(0.2, 0.8) + compare(control.first.value, 0.2) + compare(control.second.value, 0.8) + mousePress(control, control.width - control.rightPadding - 1, control.height * 0.75, Qt.LeftButton) + compare(secondPressedSpy.count, 1) + compare(secondMovedSpy.count, 1) + compare(firstPressedSpy.count, 0) + compare(firstMovedSpy.count, 0) + compare(control.second.pressed, true) + compare(control.second.value, 1.0) + compare(control.second.position, 1.0) + compare(control.first.pressed, false) + compare(control.first.value, 0.2) + compare(control.first.position, 0.2) + + mouseRelease(control, control.width - control.rightPadding - 1, control.height * 0.75, Qt.LeftButton) + compare(secondPressedSpy.count, 2) + compare(secondMovedSpy.count, 1) + compare(firstPressedSpy.count, 0) + compare(firstMovedSpy.count, 0) + compare(control.second.pressed, false) + compare(control.second.value, 1.0) + compare(control.second.position, 1.0) + compare(control.first.pressed, false) + compare(control.first.value, 0.2) + compare(control.first.position, 0.2) + } + + function test_clickFocus() { + let control = createTemporaryObject(sliderComponent, testCase) + verify(control) + + // Click on the second handle - it should get focus on press. + mousePress(control, control.second.handle.x, control.second.handle.y, Qt.LeftButton) + if (Qt.platform.os === "osx") + verify(!control.activeFocus) + else + verify(control.activeFocus) + mouseRelease(control, control.second.handle.x, control.second.handle.y, Qt.LeftButton) + + // Click on the first handle - it should get focus on press. + mousePress(control, control.first.handle.x, control.first.handle.y, Qt.LeftButton) + if (Qt.platform.os === "osx") + verify(!control.activeFocus) + else + verify(control.activeFocus) + mouseRelease(control, control.first.handle.x, control.first.handle.y, Qt.LeftButton) + } } diff --git a/tests/auto/quickcontrols/controls/data/tst_roundbutton.qml b/tests/auto/quickcontrols/controls/data/tst_roundbutton.qml index dfdd62086d..553d99a2d8 100644 --- a/tests/auto/quickcontrols/controls/data/tst_roundbutton.qml +++ b/tests/auto/quickcontrols/controls/data/tst_roundbutton.qml @@ -1,5 +1,5 @@ // Copyright (C) 2017 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only import QtQuick import QtTest @@ -18,18 +18,20 @@ TestCase { RoundButton { } } - function test_defaults() { + function init() { failOnWarning(/.?/) + } + function test_defaults() { let control = createTemporaryObject(roundButton, testCase) verify(control) } function test_radius() { - var control = createTemporaryObject(roundButton, testCase); + let control = createTemporaryObject(roundButton, testCase); verify(control); - var implicitRadius = control.radius; + let implicitRadius = control.radius; compare(implicitRadius, Math.min(control.width, control.height) / 2); control.radius = 10; @@ -46,11 +48,11 @@ TestCase { } function test_spacing() { - var control = createTemporaryObject(roundButton, testCase, { text: "Some long, long, long text" }) + let control = createTemporaryObject(roundButton, testCase, { text: "Some long, long, long text" }) verify(control) verify(control.contentItem.implicitWidth + control.leftPadding + control.rightPadding > control.background.implicitWidth) - var textLabel = findChild(control.contentItem, "label") + let textLabel = findChild(control.contentItem, "label") verify(textLabel) // The implicitWidth of the IconLabel that all buttons use as their contentItem @@ -79,7 +81,7 @@ TestCase { } function test_display(data) { - var control = createTemporaryObject(roundButton, testCase, { + let control = createTemporaryObject(roundButton, testCase, { text: "RoundButton", display: data.display, "icon.source": "qrc:/qt-project.org/imports/QtQuick/Controls/Basic/images/check.png", @@ -88,8 +90,8 @@ TestCase { verify(control) compare(control.icon.source, "qrc:/qt-project.org/imports/QtQuick/Controls/Basic/images/check.png") - var iconImage = findChild(control.contentItem, "image") - var textLabel = findChild(control.contentItem, "label") + let iconImage = findChild(control.contentItem, "image") + let textLabel = findChild(control.contentItem, "label") switch (control.display) { case RoundButton.IconOnly: diff --git a/tests/auto/quickcontrols/controls/data/tst_scrollbar.qml b/tests/auto/quickcontrols/controls/data/tst_scrollbar.qml index f26d8f5cb0..2031019157 100644 --- a/tests/auto/quickcontrols/controls/data/tst_scrollbar.qml +++ b/tests/auto/quickcontrols/controls/data/tst_scrollbar.qml @@ -1,5 +1,5 @@ // Copyright (C) 2017 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only import QtQuick import QtTest @@ -28,6 +28,7 @@ TestCase { Component { id: scrollBar ScrollBar { + objectName: "scrollBar" padding: 0 minimumSize: 0 } @@ -43,6 +44,7 @@ TestCase { Component { id: flickable Flickable { + objectName: "flickable" width: 100 height: 100 contentWidth: 200 @@ -52,19 +54,21 @@ TestCase { } } - function test_defaults() { + function init() { failOnWarning(/.?/) + } + function test_defaults() { let control = createTemporaryObject(defaultScrollBar, testCase) verify(control) } function test_attach() { - var container = createTemporaryObject(flickable, testCase) + let container = createTemporaryObject(flickable, testCase) verify(container) waitForRendering(container) - var vertical = scrollBar.createObject() + let vertical = scrollBar.createObject(null, { objectName: "verticalScrollBar" }) verify(!vertical.parent) compare(vertical.size, 0.0) compare(vertical.position, 0.0) @@ -94,7 +98,7 @@ TestCase { container.width += 10 compare(vertical.x, 123) - var horizontal = createTemporaryObject(scrollBar, null) + let horizontal = createTemporaryObject(scrollBar, null, { objectName: "horizontalScrollBar" }) verify(!horizontal.parent) compare(horizontal.size, 0.0) compare(horizontal.position, 0.0) @@ -124,7 +128,7 @@ TestCase { container.height += 10 compare(horizontal.y, 123) - var velocity = container.maximumFlickVelocity + let velocity = container.maximumFlickVelocity compare(container.flicking, false) container.flick(-velocity, -velocity) @@ -146,16 +150,16 @@ TestCase { compare(horizontal.size, container.visibleArea.widthRatio) compare(horizontal.position, container.visibleArea.xPosition) - var oldY = vertical.y - var oldHeight = vertical.height + let oldY = vertical.y + let oldHeight = vertical.height vertical.parent = testCase vertical.y -= 10 container.height += 10 compare(vertical.y, oldY - 10) compare(vertical.height, oldHeight) - var oldX = horizontal.x - var oldWidth = horizontal.width + let oldX = horizontal.x + let oldWidth = horizontal.width horizontal.parent = testCase horizontal.x -= 10 container.width += 10 @@ -216,12 +220,12 @@ TestCase { } function test_mouse(data) { - var control = createTemporaryObject(scrollBarWithDefaultPadding, testCase, data.properties) + let control = createTemporaryObject(scrollBarWithDefaultPadding, testCase, data.properties) verify(control) - var grooveRange = getGrooveRange(control) + let grooveRange = getGrooveRange(control) - var pressedSpy = signalSpy.createObject(control, {target: control, signalName: "pressedChanged"}) + let pressedSpy = signalSpy.createObject(control, {target: control, signalName: "pressedChanged"}) verify(pressedSpy.valid) mousePress(control, grooveRange.start.x, grooveRange.start.y, Qt.LeftButton) @@ -268,7 +272,7 @@ TestCase { fuzzyCompare(control.position, 0.25, 0.01) if (control.__decreaseVisual.indicator !== null) { - var p = control.__decreaseVisual.indicator.mapToItem(control, Qt.point(0, 0)) + let p = control.__decreaseVisual.indicator.mapToItem(control, Qt.point(0, 0)) mousePress(control, p.x, p.y, Qt.LeftButton) compare(pressedSpy.count, 4) compare(control.pressed, false) @@ -296,18 +300,18 @@ TestCase { } function test_touch(data) { - var control = createTemporaryObject(scrollBar, testCase, data.properties) + let control = createTemporaryObject(scrollBar, testCase, data.properties) verify(control) - var pressedSpy = signalSpy.createObject(control, {target: control, signalName: "pressedChanged"}) + let pressedSpy = signalSpy.createObject(control, {target: control, signalName: "pressedChanged"}) verify(pressedSpy.valid) control.width += (control.leftPadding + control.rightPadding) control.height += (control.topPadding + control.bottomPadding) - var availableSlideWidth = 0 - var availableSlideHeight = 0 + let availableSlideWidth = 0 + let availableSlideHeight = 0 - var p0 = {} + let p0 = {} if (control.orientation === Qt.Horizontal) { availableSlideWidth = control.width - control.rightPadding - control.leftPadding p0 = { x = control.leftPadding, y = control.height/2 } @@ -316,7 +320,7 @@ TestCase { p0 = { x = control.width/2, y = control.topPadding} } - var touch = touchEvent(control) + let touch = touchEvent(control) touch.press(0, control, p0.x, p0.y).commit() compare(pressedSpy.count, 1) @@ -360,23 +364,23 @@ TestCase { } function test_multiTouch() { - var control1 = createTemporaryObject(scrollBar, testCase) + let control1 = createTemporaryObject(scrollBar, testCase) verify(control1) control1.height = 200 + (control1.topPadding + control1.bottomPadding) - var grooveRange = getGrooveRange(control1) + let grooveRange = getGrooveRange(control1) - var pressedCount1 = 0 - var movedCount1 = 0 + let pressedCount1 = 0 + let movedCount1 = 0 - var pressedSpy1 = signalSpy.createObject(control1, {target: control1, signalName: "pressedChanged"}) + let pressedSpy1 = signalSpy.createObject(control1, {target: control1, signalName: "pressedChanged"}) verify(pressedSpy1.valid) - var positionSpy1 = signalSpy.createObject(control1, {target: control1, signalName: "positionChanged"}) + let positionSpy1 = signalSpy.createObject(control1, {target: control1, signalName: "positionChanged"}) verify(positionSpy1.valid) - var touch = touchEvent(control1) + let touch = touchEvent(control1) touch.press(0, control1, grooveRange.start.x, grooveRange.start.y).commit().move(0, control1, grooveRange.end.x+1, grooveRange.end.y+1).commit() compare(pressedSpy1.count, ++pressedCount1) @@ -394,17 +398,17 @@ TestCase { compare(control1.pressed, true) compare(control1.position, 1.0) - var control2 = createTemporaryObject(scrollBar, testCase, {y: control1.height}) + let control2 = createTemporaryObject(scrollBar, testCase, {y: control1.height}) verify(control2) control2.height = 200 + (control2.topPadding + control2.bottomPadding) - var pressedCount2 = 0 - var movedCount2 = 0 + let pressedCount2 = 0 + let movedCount2 = 0 - var pressedSpy2 = signalSpy.createObject(control2, {target: control2, signalName: "pressedChanged"}) + let pressedSpy2 = signalSpy.createObject(control2, {target: control2, signalName: "pressedChanged"}) verify(pressedSpy2.valid) - var positionSpy2 = signalSpy.createObject(control2, {target: control2, signalName: "positionChanged"}) + let positionSpy2 = signalSpy.createObject(control2, {target: control2, signalName: "positionChanged"}) verify(positionSpy2.valid) // press the second scrollbar @@ -457,7 +461,7 @@ TestCase { } function test_increase_decrease(data) { - var control = createTemporaryObject(scrollBar, testCase, {position: 0.5, active: data.active}) + let control = createTemporaryObject(scrollBar, testCase, {position: 0.5, active: data.active}) verify(control) if (data.increase) { @@ -479,18 +483,18 @@ TestCase { } function test_stepSize(data) { - var control = createTemporaryObject(scrollBar, testCase, {stepSize: data.stepSize}) + let control = createTemporaryObject(scrollBar, testCase, {stepSize: data.stepSize}) verify(control) compare(control.stepSize, data.stepSize) compare(control.position, 0.0) - var count = 10 + let count = 10 if (data.stepSize !== 0.0) count = 1.0 / data.stepSize // increase until 1.0 - for (var i = 1; i <= count; ++i) { + for (let i = 1; i <= count; ++i) { control.increase() compare(control.position, i / count) } @@ -498,7 +502,7 @@ TestCase { compare(control.position, 1.0) // decrease until 0.0 - for (var d = count - 1; d >= 0; --d) { + for (let d = count - 1; d >= 0; --d) { control.decrease() compare(control.position, d / count) } @@ -514,7 +518,7 @@ TestCase { } function test_padding(data) { - var control = createTemporaryObject(scrollBar, testCase, data.properties) + let control = createTemporaryObject(scrollBar, testCase, data.properties) mousePress(control, control.leftPadding + control.availableWidth * 0.5, control.topPadding + control.availableHeight * 0.5, Qt.LeftButton) mouseRelease(control, control.leftPadding + control.availableWidth * 0.5, control.topPadding + control.availableHeight * 0.5, Qt.LeftButton) @@ -528,7 +532,7 @@ TestCase { } function test_mirrored() { - var container = createTemporaryObject(flickable, testCase) + let container = createTemporaryObject(flickable, testCase) verify(container) waitForRendering(container) @@ -547,7 +551,7 @@ TestCase { } function test_hover(data) { - var control = createTemporaryObject(scrollBar, testCase, {hoverEnabled: data.hoverEnabled, interactive: data.interactive}) + let control = createTemporaryObject(scrollBar, testCase, {hoverEnabled: data.hoverEnabled, interactive: data.interactive}) verify(control) compare(control.hovered, false) @@ -579,14 +583,14 @@ TestCase { } function test_snapMode_mouse(data) { - var control = createTemporaryObject(scrollBar, testCase, {snapMode: data.snapMode, orientation: Qt.Horizontal, stepSize: data.stepSize, size: data.size, width: data.width}) + let control = createTemporaryObject(scrollBar, testCase, {snapMode: data.snapMode, orientation: Qt.Horizontal, stepSize: data.stepSize, size: data.size, width: data.width}) verify(control) // In case the slider is surrounded with decrease/increase buttons // Adjust slider width so that slider area is a whole number (to avoid rounding errors) control.width += control.leftPadding + control.rightPadding function snappedPosition(pos) { - var effectiveStep = control.stepSize * (1.0 - control.size) + let effectiveStep = control.stepSize * (1.0 - control.size) return Math.round(pos / effectiveStep) * effectiveStep } @@ -594,14 +598,14 @@ TestCase { return Math.max(0, Math.min(pos, 1.0 - control.size)) } - var minHandlePos = control.leftPadding - var maxHandlePos = control.width - control.rightPadding - var availableSlideWidth = maxHandlePos - minHandlePos + let minHandlePos = control.leftPadding + let maxHandlePos = control.width - control.rightPadding + let availableSlideWidth = maxHandlePos - minHandlePos mousePress(control, minHandlePos, 0) compare(control.position, 0) mouseMove(control, minHandlePos + availableSlideWidth * 0.3, 0) - var expectedMovePos = 0.3 + let expectedMovePos = 0.3 if (control.snapMode === ScrollBar.SnapAlways) { expectedMovePos = snappedPosition(expectedMovePos) verify(expectedMovePos !== 0.3) @@ -609,7 +613,7 @@ TestCase { compare(control.position, expectedMovePos) mouseRelease(control, minHandlePos + availableSlideWidth * 0.75, 0) - var expectedReleasePos = 0.75 + let expectedReleasePos = 0.75 if (control.snapMode !== ScrollBar.NoSnap) { expectedReleasePos = snappedPosition(expectedReleasePos) verify(expectedReleasePos !== 0.75) @@ -619,10 +623,10 @@ TestCase { control.position = 0 mousePress(control, minHandlePos, 0) - var steps = 0 - var prevPos = 0 + let steps = 0 + let prevPos = 0 - for (var x = minHandlePos; x < maxHandlePos; ++x) { + for (let x = minHandlePos; x < maxHandlePos; ++x) { mouseMove(control, x, 0) expectedMovePos = boundPosition((x - minHandlePos) / availableSlideWidth) if (control.snapMode === ScrollBar.SnapAlways) @@ -643,14 +647,14 @@ TestCase { } function test_snapMode_touch(data) { - var control = createTemporaryObject(scrollBar, testCase, {snapMode: data.snapMode, orientation: Qt.Horizontal, stepSize: data.stepSize, size: data.size, width: data.width}) + let control = createTemporaryObject(scrollBar, testCase, {snapMode: data.snapMode, orientation: Qt.Horizontal, stepSize: data.stepSize, size: data.size, width: data.width}) verify(control) // In case the slider is surrounded with decrease/increase buttons // Adjust slider width so that slider area is a whole number (to avoid rounding errors) control.width += control.leftPadding + control.rightPadding function snappedPosition(pos) { - var effectiveStep = control.stepSize * (1.0 - control.size) + let effectiveStep = control.stepSize * (1.0 - control.size) return Math.round(pos / effectiveStep) * effectiveStep } @@ -658,16 +662,16 @@ TestCase { return Math.max(0, Math.min(pos, 1.0 - control.size)) } - var touch = touchEvent(control) + let touch = touchEvent(control) - var minHandlePos = control.leftPadding - var maxHandlePos = control.width - control.rightPadding - var availableSlideWidth = maxHandlePos - minHandlePos + let minHandlePos = control.leftPadding + let maxHandlePos = control.width - control.rightPadding + let availableSlideWidth = maxHandlePos - minHandlePos touch.press(0, control, minHandlePos, 0).commit() compare(control.position, 0) touch.move(0, control, minHandlePos + availableSlideWidth*0.3, 0).commit() - var expectedMovePos = 0.3 + let expectedMovePos = 0.3 if (control.snapMode === ScrollBar.SnapAlways) { expectedMovePos = snappedPosition(expectedMovePos) verify(expectedMovePos !== 0.3) @@ -675,7 +679,7 @@ TestCase { compare(control.position, expectedMovePos) touch.release(0, control, minHandlePos + availableSlideWidth*0.75, 0).commit() - var expectedReleasePos = 0.75 + let expectedReleasePos = 0.75 if (control.snapMode !== ScrollBar.NoSnap) { expectedReleasePos = snappedPosition(expectedReleasePos) verify(expectedReleasePos !== 0.75) @@ -685,10 +689,10 @@ TestCase { control.position = 0 touch.press(0, control, minHandlePos, 0).commit() - var steps = 0 - var prevPos = 0 + let steps = 0 + let prevPos = 0 - for (var x = minHandlePos; x < maxHandlePos; ++x) { + for (let x = minHandlePos; x < maxHandlePos; ++x) { touch.move(0, control, x, 0).commit() expectedMovePos = boundPosition((x - minHandlePos) / availableSlideWidth) if (control.snapMode === ScrollBar.SnapAlways) @@ -712,7 +716,7 @@ TestCase { } function test_interactive(data) { - var control = createTemporaryObject(scrollBar, testCase, {interactive: data.interactive}) + let control = createTemporaryObject(scrollBar, testCase, {interactive: data.interactive}) verify(control) compare(control.interactive, data.interactive) @@ -759,7 +763,7 @@ TestCase { } function test_policy() { - var control = createTemporaryObject(scrollBar, testCase, {active: true}) + let control = createTemporaryObject(scrollBar, testCase, {active: true}) verify(control) compare(ScrollBar.AsNeeded, Qt.ScrollBarAsNeeded) @@ -769,8 +773,8 @@ TestCase { compare(control.visible, true) compare(control.policy, ScrollBar.AsNeeded) - var windowsStyle = false - var macOSStyle = false + let windowsStyle = false + let macOSStyle = false if (control.background instanceof NativeStyle.StyleItem) { windowsStyle = Qt.platform.pluginName === "windows" macOSStyle = Qt.platform.pluginName === "cocoa" @@ -794,14 +798,14 @@ TestCase { } function test_overshoot() { - var container = createTemporaryObject(flickable, testCase) + let container = createTemporaryObject(flickable, testCase) verify(container) waitForRendering(container) - var vertical = scrollBar.createObject(container, {size: 0.5}) + let vertical = scrollBar.createObject(container, {size: 0.5}) container.ScrollBar.vertical = vertical - var horizontal = scrollBar.createObject(container, {size: 0.5}) + let horizontal = scrollBar.createObject(container, {size: 0.5}) container.ScrollBar.horizontal = horizontal // negative vertical overshoot (pos < 0) @@ -826,7 +830,7 @@ TestCase { } function test_orientation() { - var control = createTemporaryObject(scrollBar, testCase) + let control = createTemporaryObject(scrollBar, testCase) verify(control) compare(control.orientation, Qt.Vertical) @@ -840,10 +844,10 @@ TestCase { } function test_flashing() { - var control = createTemporaryObject(scrollBar, testCase, {size: 0.2}) + let control = createTemporaryObject(scrollBar, testCase, {size: 0.2}) verify(control) - var activeSpy = signalSpy.createObject(control, {target: control, signalName: "activeChanged"}) + let activeSpy = signalSpy.createObject(control, {target: control, signalName: "activeChanged"}) verify(activeSpy.valid) compare(control.active, false) @@ -884,11 +888,11 @@ TestCase { } function test_minimumSize() { - var container = createTemporaryObject(flickable, testCase) + let container = createTemporaryObject(flickable, testCase) verify(container) waitForRendering(container) - var vertical = scrollBar.createObject(container, {minimumSize: 0.1}) + let vertical = scrollBar.createObject(container, {minimumSize: 0.1}) container.ScrollBar.vertical = vertical compare(container.visibleArea.heightRatio, 0.5) @@ -932,7 +936,7 @@ TestCase { } function test_resize() { - var vertical = createTemporaryObject(scrollBar, testCase, { height:200, orientation: Qt.Vertical, size: 0.5, position: 0.5 }) + let vertical = createTemporaryObject(scrollBar, testCase, { height:200, orientation: Qt.Vertical, size: 0.5, position: 0.5 }) verify(vertical) vertical.size = 0.8 @@ -943,7 +947,7 @@ TestCase { compare(vertical.visualPosition, 0.2) - var horizontal = createTemporaryObject(scrollBar, testCase, { width:200, orientation: Qt.Horizontal, size: 0.5, position: 0.5 }) + let horizontal = createTemporaryObject(scrollBar, testCase, { width:200, orientation: Qt.Horizontal, size: 0.5, position: 0.5 }) verify(horizontal) horizontal.size = 0.8 @@ -955,7 +959,7 @@ TestCase { } function test_setting_invalid_property_values() { - var control = createTemporaryObject(scrollBar, testCase, {size: 2.0, minimumSize: -1.0}) + let control = createTemporaryObject(scrollBar, testCase, {size: 2.0, minimumSize: -1.0}) verify(control) // check that the values are within the expected range @@ -987,4 +991,19 @@ TestCase { compare(oldPosition, control.position) compare(oldStepSize, control.stepSize) } + + function test_visualSizeChanged_is_emitted_by_setSize() { + const control = createTemporaryObject(scrollBar, testCase, {size: 0.2}) + verify(control) + + const spy = signalSpy.createObject(control, {target: control, signalName: "visualSizeChanged"}) + verify(spy.valid) + + compare(control.visualSize, 0.2) + + control.size = 0.5 + + compare(spy.count, 1) + compare(control.visualSize, 0.5) + } } diff --git a/tests/auto/quickcontrols/controls/data/tst_scrollindicator.qml b/tests/auto/quickcontrols/controls/data/tst_scrollindicator.qml index d87e29f980..74713f930c 100644 --- a/tests/auto/quickcontrols/controls/data/tst_scrollindicator.qml +++ b/tests/auto/quickcontrols/controls/data/tst_scrollindicator.qml @@ -1,5 +1,5 @@ // Copyright (C) 2017 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only import QtQuick import QtTest @@ -35,19 +35,21 @@ TestCase { } } - function test_defaults() { + function init() { failOnWarning(/.?/) + } + function test_defaults() { let control = createTemporaryObject(scrollIndicator, testCase) verify(control) } function test_attach() { - var container = createTemporaryObject(flickable, testCase) + let container = createTemporaryObject(flickable, testCase) verify(container) waitForRendering(container) - var vertical = createTemporaryObject(scrollIndicator, null) + let vertical = createTemporaryObject(scrollIndicator, null) verify(!vertical.parent) compare(vertical.size, 0.0) compare(vertical.position, 0.0) @@ -77,7 +79,7 @@ TestCase { container.width += 10 compare(vertical.x, 123) - var horizontal = createTemporaryObject(scrollIndicator, null) + let horizontal = createTemporaryObject(scrollIndicator, null) verify(!horizontal.parent) compare(horizontal.size, 0.0) compare(horizontal.position, 0.0) @@ -107,7 +109,7 @@ TestCase { container.height += 10 compare(horizontal.y, 123) - var velocity = container.maximumFlickVelocity + let velocity = container.maximumFlickVelocity compare(container.flicking, false) container.flick(-velocity, -velocity) @@ -129,16 +131,16 @@ TestCase { compare(horizontal.size, container.visibleArea.widthRatio) compare(horizontal.position, container.visibleArea.xPosition) - var oldY = vertical.y - var oldHeight = vertical.height + let oldY = vertical.y + let oldHeight = vertical.height vertical.parent = testCase vertical.y -= 10 container.height += 10 compare(vertical.y, oldY - 10) compare(vertical.height, oldHeight) - var oldX = horizontal.x - var oldWidth = horizontal.width + let oldX = horizontal.x + let oldWidth = horizontal.width horizontal.parent = testCase horizontal.x -= 10 container.width += 10 @@ -152,14 +154,14 @@ TestCase { } function test_overshoot() { - var container = createTemporaryObject(flickable, testCase) + let container = createTemporaryObject(flickable, testCase) verify(container) waitForRendering(container) - var vertical = scrollIndicator.createObject(container, {size: 0.5}) + let vertical = scrollIndicator.createObject(container, {size: 0.5}) container.ScrollIndicator.vertical = vertical - var horizontal = scrollIndicator.createObject(container, {size: 0.5}) + let horizontal = scrollIndicator.createObject(container, {size: 0.5}) container.ScrollIndicator.horizontal = horizontal // negative vertical overshoot (pos < 0) @@ -184,7 +186,7 @@ TestCase { } function test_orientation() { - var control = createTemporaryObject(scrollIndicator, testCase) + let control = createTemporaryObject(scrollIndicator, testCase) verify(control) compare(control.orientation, Qt.Vertical) @@ -199,10 +201,10 @@ TestCase { // QTBUG-61785 function test_mouseArea() { - var ma = createTemporaryObject(mouseArea, testCase, {width: testCase.width, height: testCase.height}) + let ma = createTemporaryObject(mouseArea, testCase, {width: testCase.width, height: testCase.height}) verify(ma) - var control = scrollIndicator.createObject(ma, {active: true, size: 0.9, width: testCase.width, height: testCase.height}) + let control = scrollIndicator.createObject(ma, {active: true, size: 0.9, width: testCase.width, height: testCase.height}) verify(control) mousePress(control) @@ -211,7 +213,7 @@ TestCase { mouseRelease(control) verify(!ma.pressed) - var touch = touchEvent(control) + let touch = touchEvent(control) touch.press(0, control).commit() verify(ma.pressed) @@ -220,11 +222,11 @@ TestCase { } function test_minimumSize() { - var container = createTemporaryObject(flickable, testCase) + let container = createTemporaryObject(flickable, testCase) verify(container) waitForRendering(container) - var vertical = scrollIndicator.createObject(container, {minimumSize: 0.1}) + let vertical = scrollIndicator.createObject(container, {minimumSize: 0.1}) container.ScrollIndicator.vertical = vertical compare(container.visibleArea.heightRatio, 0.5) @@ -268,7 +270,7 @@ TestCase { } function test_resize() { - var vertical = createTemporaryObject(scrollIndicator, testCase, { height:200, orientation: Qt.Vertical, size: 0.5, position: 0.5 }) + let vertical = createTemporaryObject(scrollIndicator, testCase, { height:200, orientation: Qt.Vertical, size: 0.5, position: 0.5 }) verify(vertical) vertical.size = 0.8 @@ -279,7 +281,7 @@ TestCase { compare(vertical.visualPosition, 0.2) - var horizontal = createTemporaryObject(scrollIndicator, testCase, { width:200, orientation: Qt.Horizontal, size: 0.5, position: 0.5 }) + let horizontal = createTemporaryObject(scrollIndicator, testCase, { width:200, orientation: Qt.Horizontal, size: 0.5, position: 0.5 }) verify(horizontal) horizontal.size = 0.8 diff --git a/tests/auto/quickcontrols/controls/data/tst_scrollview.qml b/tests/auto/quickcontrols/controls/data/tst_scrollview.qml index e5600830a8..622f341f78 100644 --- a/tests/auto/quickcontrols/controls/data/tst_scrollview.qml +++ b/tests/auto/quickcontrols/controls/data/tst_scrollview.qml @@ -1,5 +1,5 @@ // Copyright (C) 2017 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only import QtQuick import QtTest @@ -146,6 +146,7 @@ TestCase { } } } + Component { id: scrollableTextAreaWithSibling ScrollView { @@ -156,21 +157,23 @@ TestCase { } } - function test_defaults() { + function init() { failOnWarning(/.?/) + } + function test_defaults() { let control = createTemporaryObject(scrollView, testCase) verify(control) } function test_scrollBars() { - var control = createTemporaryObject(scrollView, testCase, {width: 200, height: 200}) + let control = createTemporaryObject(scrollView, testCase, {width: 200, height: 200}) verify(control) - var vertical = control.ScrollBar.vertical + let vertical = control.ScrollBar.vertical verify(vertical) - var horizontal = control.ScrollBar.horizontal + let horizontal = control.ScrollBar.horizontal verify(horizontal) control.contentHeight = 400 @@ -188,6 +191,18 @@ TestCase { horizontal.increase() verify(horizontal.position > 0) compare(control.contentItem.visibleArea.xPosition, horizontal.position) + + vertical.policy = ScrollBar.AlwaysOn + horizontal.policy = ScrollBar.AlwaysOn + + verify(control.effectiveScrollBarWidth > 0) + verify(control.effectiveScrollBarHeight > 0) + + vertical.policy = ScrollBar.AlwaysOff + horizontal.policy = ScrollBar.AlwaysOff + + compare(control.effectiveScrollBarWidth, 0) + compare(control.effectiveScrollBarHeight, 0) } function test_oneChild_data() { @@ -198,14 +213,14 @@ TestCase { } function test_oneChild(data) { - var control = createTemporaryObject(data.component, testCase) + let control = createTemporaryObject(data.component, testCase) verify(control) - var flickable = control.contentItem + let flickable = control.contentItem verify(flickable.hasOwnProperty("contentX")) verify(flickable.hasOwnProperty("contentY")) - var label = flickable.contentItem.children[0] + let label = flickable.contentItem.children[0] compare(label.text, "ABC") compare(control.implicitWidth, label.implicitWidth) @@ -229,34 +244,34 @@ TestCase { } function test_multipleChildren() { - var control = createTemporaryObject(scrollableLabels, testCase) + let control = createTemporaryObject(scrollableLabels, testCase) verify(control) - var flickable = control.contentItem + let flickable = control.contentItem verify(flickable.hasOwnProperty("contentX")) verify(flickable.hasOwnProperty("contentY")) compare(control.contentChildren, flickable.contentItem.children) - var label1 = control.contentChildren[0] + let label1 = control.contentChildren[0] compare(label1.text, "First") - var label2 = control.contentChildren[1] + let label2 = control.contentChildren[1] compare(label2.text, "Second") - var label3 = control.contentChildren[2] + let label3 = control.contentChildren[2] compare(label3.text, "Third") - var expectedContentHeight = label1.implicitHeight + label2.implicitHeight + label3.implicitHeight + let expectedContentHeight = label1.implicitHeight + label2.implicitHeight + label3.implicitHeight compare(control.contentHeight, expectedContentHeight) compare(flickable.contentHeight, expectedContentHeight) } function test_listView() { - var control = createTemporaryObject(scrollableListView, testCase) + let control = createTemporaryObject(scrollableListView, testCase) verify(control) - var listview = control.contentItem + let listview = control.contentItem verify(listview.hasOwnProperty("contentX")) verify(listview.hasOwnProperty("contentY")) verify(listview.hasOwnProperty("model")) @@ -272,10 +287,10 @@ TestCase { // children, even if the flickable has an empty or negative content // size. Some flickables (e.g ListView) sets a negative // contentWidth on purpose, which should be respected. - var scrollview = createTemporaryObject(scrollableFlickable, testCase) + let scrollview = createTemporaryObject(scrollableFlickable, testCase) verify(scrollview) - var flickable = scrollview.contentItem + let flickable = scrollview.contentItem verify(flickable.hasOwnProperty("contentX")) verify(flickable.hasOwnProperty("contentY")) @@ -290,10 +305,10 @@ TestCase { // not the flickable, then those values will be forwarded and used // by the flickable (rather than trying to calculate the content size // based on the flickables children). - var scrollview = createTemporaryObject(scrollableWithContentSize, testCase) + let scrollview = createTemporaryObject(scrollableWithContentSize, testCase) verify(scrollview) - var flickable = scrollview.contentItem + let flickable = scrollview.contentItem verify(flickable.hasOwnProperty("contentX")) verify(flickable.hasOwnProperty("contentY")) @@ -307,10 +322,10 @@ TestCase { // Check that if both the scrollview and the flickable has // contentWidth/Height set (which is an inconsistency/fault // by the app), the content size of the scrollview wins. - var scrollview = createTemporaryObject(scrollableAndFlicableWithContentSize, testCase) + let scrollview = createTemporaryObject(scrollableAndFlicableWithContentSize, testCase) verify(scrollview) - var flickable = scrollview.contentItem + let flickable = scrollview.contentItem verify(flickable.hasOwnProperty("contentX")) verify(flickable.hasOwnProperty("contentY")) @@ -321,14 +336,14 @@ TestCase { } function test_flickableWithExplicitContentSize() { - var control = createTemporaryObject(emptyFlickable, testCase) + let control = createTemporaryObject(emptyFlickable, testCase) verify(control) - var flickable = control.contentItem + let flickable = control.contentItem verify(flickable.hasOwnProperty("contentX")) verify(flickable.hasOwnProperty("contentY")) - var flickableContentSize = 1000; + let flickableContentSize = 1000; flickable.contentWidth = flickableContentSize; flickable.contentHeight = flickableContentSize; @@ -354,13 +369,13 @@ TestCase { } function test_mouse() { - var control = createTemporaryObject(scrollView, testCase, {width: 200, height: 200, contentHeight: 400}) + let control = createTemporaryObject(scrollView, testCase, {width: 200, height: 200, contentHeight: 400}) verify(control) mousePress(control, control.width / 2, control.height / 2, Qt.LeftButton) compare(control.contentItem.contentY, 0) - for (var y = control.height / 2; y >= 0; --y) { + for (let y = control.height / 2; y >= 0; --y) { mouseMove(control, control.width / 2, y, 10) compare(control.contentItem.contentY, 0) } @@ -370,10 +385,10 @@ TestCase { } function test_hover() { - var control = createTemporaryObject(scrollView, testCase, {width: 200, height: 200, contentHeight: 400}) + let control = createTemporaryObject(scrollView, testCase, {width: 200, height: 200, contentHeight: 400}) verify(control) - var vertical = control.ScrollBar.vertical + let vertical = control.ScrollBar.vertical verify(vertical) vertical.hoverEnabled = true @@ -385,10 +400,10 @@ TestCase { } function test_wheel() { - var control = createTemporaryObject(scrollView, testCase, {width: 200, height: 200, contentHeight: 400}) + let control = createTemporaryObject(scrollView, testCase, {width: 200, height: 200, contentHeight: 400}) verify(control) - var vertical = control.ScrollBar.vertical + let vertical = control.ScrollBar.vertical verify(vertical) mouseWheel(control, control.width / 2, control.height / 2, 0, -120) @@ -398,21 +413,21 @@ TestCase { } function test_touch() { - var control = createTemporaryObject(scrollView, testCase, {width: 200, height: 200, contentHeight: 400}) + let control = createTemporaryObject(scrollView, testCase, {width: 200, height: 200, contentHeight: 400}) verify(control) - var vertical = control.ScrollBar.vertical + let vertical = control.ScrollBar.vertical verify(vertical) - var touch = touchEvent(control) + let touch = touchEvent(control) touch.press(0, control, control.width / 2, control.height / 2).commit() compare(control.contentItem.contentY, 0) compare(vertical.active, false) compare(vertical.interactive, false) - var maxContentY = 0 - for (var y = control.height / 2; y >= 0; --y) { + let maxContentY = 0 + for (let y = control.height / 2; y >= 0; --y) { touch.move(0, control, control.width / 2, y).commit() maxContentY = Math.max(maxContentY, control.contentItem.contentY) } @@ -425,7 +440,7 @@ TestCase { } function test_keys() { - var control = createTemporaryObject(scrollView, testCase, {width: 200, height: 200, contentWidth: 400, contentHeight: 400}) + let control = createTemporaryObject(scrollView, testCase, {width: 200, height: 200, contentWidth: 400, contentHeight: 400}) verify(control) // If the viewport is smaller than the size of the ScrollView // (like windows style does due to its opaque scrollbars), @@ -436,31 +451,31 @@ TestCase { control.forceActiveFocus() verify(control.activeFocus) - var vertical = control.ScrollBar.vertical + let vertical = control.ScrollBar.vertical verify(vertical) compare(vertical.position, 0.0) - for (var i = 1; i <= 10; ++i) { + for (let i = 1; i <= 10; ++i) { keyClick(Qt.Key_Down) compare(vertical.position, Math.min(0.5, i * 0.1)) } compare(vertical.position, 0.5) - for (i = 1; i <= 10; ++i) { + for (let i = 1; i <= 10; ++i) { keyClick(Qt.Key_Up) compare(vertical.position, Math.max(0.0, 0.5 - i * 0.1)) } compare(vertical.position, 0.0) - var horizontal = control.ScrollBar.horizontal + let horizontal = control.ScrollBar.horizontal verify(horizontal) compare(horizontal.position, 0.0) - for (i = 1; i <= 10; ++i) { + for (let i = 1; i <= 10; ++i) { keyClick(Qt.Key_Right) compare(horizontal.position, Math.min(0.5, i * 0.1)) } compare(horizontal.position, 0.5) - for (i = 1; i <= 10; ++i) { + for (let i = 1; i <= 10; ++i) { keyClick(Qt.Key_Left) compare(horizontal.position, Math.max(0.0, 0.5 - i * 0.1)) } @@ -469,22 +484,49 @@ TestCase { function test_textArea() { // TODO: verify no binding loop warnings (QTBUG-62325) - var control = createTemporaryObject(scrollableTextArea, testCase) + let control = createTemporaryObject(scrollableTextArea, testCase) verify(control) - var flickable = control.contentItem + let flickable = control.contentItem verify(flickable && flickable.hasOwnProperty("contentX")) - var textArea = flickable.contentItem.children[0] + let textArea = flickable.contentItem.children[0] verify(textArea && textArea.hasOwnProperty("text")) compare(control.contentWidth, flickable.contentWidth) compare(control.contentHeight, flickable.contentHeight) } + Component { + id: scrollableTextAreaWithPadding + + ScrollView { + TextArea { + text: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas id dignissim ipsum. Nam molestie nisl turpis." + wrapMode: TextArea.WordWrap + leftPadding: 1 + topPadding: 1 + } + } + } + + function test_textAreaWithPadding() { + let control = createTemporaryObject(scrollableTextAreaWithPadding, testCase) + verify(control) + + let flickable = control.contentItem + verify(flickable) + + let textArea = flickable.contentItem.children[0] + verify(textArea) + + compare(control.contentWidth, flickable.contentWidth) + compare(control.contentHeight, flickable.contentHeight) + } + function test_textAreaWithSibling() { // Checks that it does not crash when the ScrollView is deleted - var control = createTemporaryObject(scrollableTextAreaWithSibling, testCase) + let control = createTemporaryObject(scrollableTextAreaWithSibling, testCase) verify(control) } @@ -590,6 +632,7 @@ TestCase { id: bindingToContentItemAndStandaloneFlickable Item { + objectName: "container" width: 200 height: 200 @@ -628,7 +671,7 @@ TestCase { verify(verticalScrollBar.visible) verify(horizontalScrollBar.visible) - mouseDrag(verticalScrollBar, verticalScrollBar.width / 2, verticalScrollBar.height / 2, 0, 50) + mouseWheel(control, control.width / 2, control.height / 2, 0, -120) verify(verticalScrollBar.active) verify(horizontalScrollBar.active) } @@ -637,6 +680,7 @@ TestCase { id: contentItemAssignedImperatively Item { + objectName: "container" width: 100 height: 100 @@ -644,6 +688,7 @@ TestCase { ListView { id: listView + objectName: "customListView" model: 20 delegate: Text { text: modelData @@ -662,11 +707,59 @@ TestCase { } // Tests that a ListView declared before the ScrollView (as the QObject destruction order - // is relevant for the bug) and assigned imperatively to ScrollView does not cause a crash - // on exit. + // is relevant for the bug) and assigned imperatively to ScrollView does not cause: + // - a crash on exit + // - scroll bars that should be hidden to be visible function test_contentItemAssignedImperatively() { let root = createTemporaryObject(contentItemAssignedImperatively, testCase) verify(root) + + let control = root.scrollView + let flickable = control.contentItem + compare(flickable.parent, control) + + let horizontalScrollBar = control.ScrollBar.horizontal + let verticalScrollBar = control.ScrollBar.vertical + // The horizontal ScrollBar's policy is set to AlwaysOff, so it shouldn't ever be visible. + verify(!horizontalScrollBar.visible) + // The vertical ScrollBar should be visible... + verify(verticalScrollBar.visible) + + // ... and it should become active when the ScrollView is scrolled. + mouseWheel(control, control.width / 2, control.height / 2, 0, -120) + verify(verticalScrollBar.active) + // Shouldn't crash. } + + Component { + id: scrollViewContentItemComp + + ScrollView { + id: scrollView + anchors.fill: parent + Column { + width: parent.width + Repeater { + model: 20 + Rectangle { + width: scrollView.width + height: 60 + color: (index % 2 == 0) ? "red" : "green" + } + } + } + } + } + + function test_scrollViewContentItemSize() { + let scrollview = createTemporaryObject(scrollViewContentItemComp, testCase) + verify(scrollview) + let contentItem = scrollview.contentItem + waitForRendering(contentItem) + compare(contentItem.contentWidth, 400) + compare(contentItem.contentHeight, 1200) + compare(scrollview.contentWidth, 400) + compare(scrollview.contentHeight, 1200) + } } diff --git a/tests/auto/quickcontrols/controls/data/tst_selectionrectangle.qml b/tests/auto/quickcontrols/controls/data/tst_selectionrectangle.qml index dd4f984aa2..79a51bd4c3 100644 --- a/tests/auto/quickcontrols/controls/data/tst_selectionrectangle.qml +++ b/tests/auto/quickcontrols/controls/data/tst_selectionrectangle.qml @@ -1,5 +1,5 @@ // Copyright (C) 2021 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only import QtQuick import QtTest @@ -73,6 +73,22 @@ TestCase { } Component { + id: delegateWithTapHandlerComp + Rectangle { + implicitWidth: 100 + implicitHeight: 50 + color: selected ? "lightblue" : "transparent" + border.width: 1 + required property bool selected + + TapHandler { + // This tap handler will block the tap handler in + // QQuickTableView from being called. + } + } + } + + Component { id: tableviewComp TableView { id: tableView @@ -129,13 +145,55 @@ TestCase { } Component { + id: headerviewComp + HorizontalHeaderView { + id: headerView + clip: true + anchors.fill: parent + + model: TableModel { + TableModelColumn { display: "c1" } + TableModelColumn { display: "c2" } + TableModelColumn { display: "c3" } + TableModelColumn { display: "c4" } + TableModelColumn { display: "c5" } + TableModelColumn { display: "c6" } + TableModelColumn { display: "c7" } + TableModelColumn { display: "c8" } + rows: [ + { "c1": "v1", "c2":"v2", "c3":"v3", "c4": "v4", "c5": "v5", "c6":"v6", "c7":"v7", "c8": "v8" } + ] + } + + delegate: Rectangle { + required property bool selected + implicitWidth: cellWidth + implicitHeight: cellHeight + color: selected ? "lightblue" : "gray" + Text { text: row + "," + column } + } + + selectionModel: ItemSelectionModel { } + + property alias selectionRectangle: selectionRectangle + SelectionRectangle { + id: selectionRectangle + target: headerView + } + } + + } + + Component { id: signalSpy SignalSpy { } } - function test_defaults() { + function init() { failOnWarning(/.?/) + } + function test_defaults() { let control = createTemporaryObject(defaultSelectionRectangle, testCase) verify(control) } @@ -195,13 +253,15 @@ TestCase { function test_drag_data() { return [ - { tag: "resize enabled", resizeEnabled: true }, - { tag: "resize disabled", resizeEnabled: false }, + { tag: "resize enabled (tableview)", resizeEnabled: true, viewComp: tableviewComp }, + { tag: "resize disabled (tableview)", resizeEnabled: false, viewComp: tableviewComp }, + { tag: "resize enabled (headerview)", resizeEnabled: true, viewComp: headerviewComp }, + { tag: "resize disabled (headerview)", resizeEnabled: false, viewComp: headerviewComp }, ] } function test_drag(data) { - let tableView = createTemporaryObject(tableviewComp, testCase) + let tableView = createTemporaryObject(data.viewComp, testCase) verify(tableView) let selectionRectangle = tableView.selectionRectangle verify(selectionRectangle) @@ -222,8 +282,8 @@ TestCase { mouseDrag(tableView, 1, 1, (cellWidth * 2) - 2, 1, Qt.LeftButton) verify(tableView.selectionModel.hasSelection) compare(tableView.selectionModel.selectedIndexes.length, 2) - verify(tableView.selectionModel.isSelected(tableView.model.index(0, 0))) - verify(tableView.selectionModel.isSelected(tableView.model.index(0, 1))) + verify(tableView.selectionModel.isSelected(tableView.selectionModel.model.index(0, 0))) + verify(tableView.selectionModel.isSelected(tableView.selectionModel.model.index(0, 1))) compare(activeSpy.count, 1) compare(draggingSpy.count, 2) @@ -236,8 +296,218 @@ TestCase { // Ensure that a press and hold doesn't start a selection mousePress(tableView, 1, 1, Qt.LeftButton) - mousePress(tableView, 1, 1, Qt.LeftButton, Qt.NoModifier, 1000) + mouseRelease(tableView, 1, 1, Qt.LeftButton, Qt.NoModifier, 1000) + verify(!tableView.selectionModel.hasSelection) + } + + function test_tableView_singleSelection_data() { + return [ + { viewComp: tableviewComp }, + { viewComp: headerviewComp }, + ] + } + + function test_tableView_singleSelection(data) { + let tableView = createTemporaryObject(data.viewComp, testCase) + verify(tableView) + let selectionRectangle = tableView.selectionRectangle + verify(selectionRectangle) + + selectionRectangle.selectionMode = SelectionRectangle.Drag + tableView.selectionMode = TableView.SingleSelection + + // Try to select two cells by dragging. Only one cell should be selected. verify(!tableView.selectionModel.hasSelection) + mouseDrag(tableView, 1, 1, (cellWidth * 2) - 2, 1, Qt.LeftButton) + verify(tableView.selectionModel.hasSelection) + compare(tableView.selectionModel.selectedIndexes.length, 1) + verify(tableView.selectionModel.isSelected(tableView.selectionModel.model.index(0, 0))) + + // A control click should clear the current selection and select a new cell + mouseClick(tableView, (cellWidth * 2) - 1, 1, Qt.LeftButton, Qt.ControlModifier) + compare(tableView.selectionModel.selectedIndexes.length, 1) + verify(tableView.selectionModel.isSelected(tableView.selectionModel.model.index(0, 1))) + + // A shift click is a no-op, and doesn't change the current selection + mouseClick(tableView, 1, 1, Qt.LeftButton, Qt.ShiftModifier) + compare(tableView.selectionModel.selectedIndexes.length, 1) + verify(tableView.selectionModel.isSelected(tableView.selectionModel.model.index(0, 1))) + } + + function test_tableView_contiguousSelection_data() { + return [ + { startFromCurrentIndex: false }, + { startFromCurrentIndex: true }, + ] + } + + function test_tableView_contiguousSelection(data) { + let tableView = createTemporaryObject(tableviewComp, testCase) + verify(tableView) + let selectionRectangle = tableView.selectionRectangle + verify(selectionRectangle) + + selectionRectangle.selectionMode = SelectionRectangle.Drag + tableView.selectionMode = TableView.ContiguousSelection + + if (data.startFromCurrentIndex) { + // Click on a cell to set current index, but set no selection. + // A later shift-click should then start a new selection from the + // current cell. + mouseClick(tableView, 1, 1, Qt.LeftButton, Qt.NoModifier) + verify(!tableView.selectionModel.hasSelection) + compare(tableView.selectionModel.currentIndex, tableView.index(0, 0)) + } else { + // Start a new selection by dragging on two cells + mouseDrag(tableView, 1, 1, (cellWidth * 2) - 2, 1, Qt.LeftButton) + verify(tableView.selectionModel.hasSelection) + compare(tableView.selectionModel.selectedIndexes.length, 2) + verify(tableView.selectionModel.isSelected(tableView.model.index(0, 0))) + verify(tableView.selectionModel.isSelected(tableView.model.index(0, 1))) + } + + // A shift click should extend the selection + mouseClick(tableView, (cellWidth * 4) - 3, 1, Qt.LeftButton, Qt.ShiftModifier) + compare(tableView.selectionModel.selectedIndexes.length, 4) + verify(tableView.selectionModel.isSelected(tableView.model.index(0, 0))) + verify(tableView.selectionModel.isSelected(tableView.model.index(0, 1))) + verify(tableView.selectionModel.isSelected(tableView.model.index(0, 2))) + verify(tableView.selectionModel.isSelected(tableView.model.index(0, 3))) + + // A shift click closer to the first selected cell should shrink it again + mouseClick(tableView, (cellWidth * 3) - 2, 1, Qt.LeftButton, Qt.ShiftModifier) + compare(tableView.selectionModel.selectedIndexes.length, 3) + verify(tableView.selectionModel.isSelected(tableView.model.index(0, 0))) + verify(tableView.selectionModel.isSelected(tableView.model.index(0, 1))) + verify(tableView.selectionModel.isSelected(tableView.model.index(0, 2))) + + // A control click should clear the selection, and select a new cell + mouseClick(tableView, 1, (cellHeight * 2) - 1, Qt.LeftButton, Qt.ControlModifier) + compare(tableView.selectionModel.selectedIndexes.length, 1) + verify(tableView.selectionModel.isSelected(tableView.model.index(1, 0))) + + // A control drag should clear the selection, and select new cells + mouseDrag(tableView, 1, 1, (cellWidth * 2) - 2, 1, Qt.LeftButton, Qt.ControlModifier) + verify(tableView.selectionModel.hasSelection) + compare(tableView.selectionModel.selectedIndexes.length, 2) + verify(tableView.selectionModel.isSelected(tableView.model.index(0, 0))) + verify(tableView.selectionModel.isSelected(tableView.model.index(0, 1))) + } + + function test_tableView_extendedSelection() { + let tableView = createTemporaryObject(tableviewComp, testCase) + verify(tableView) + let selectionRectangle = tableView.selectionRectangle + verify(selectionRectangle) + + selectionRectangle.selectionMode = SelectionRectangle.Drag + // ExtendedSelection should be the default selection mode + compare(tableView.selectionMode, TableView.ExtendedSelection) + + // Select two cells by dragging + verify(!tableView.selectionModel.hasSelection) + mouseDrag(tableView, 1, 1, (cellWidth * 2) - 2, 1, Qt.LeftButton) + verify(tableView.selectionModel.hasSelection) + compare(tableView.selectionModel.selectedIndexes.length, 2) + verify(tableView.selectionModel.isSelected(tableView.model.index(0, 0))) + verify(tableView.selectionModel.isSelected(tableView.model.index(0, 1))) + + // A shift click should extend the selection + mouseClick(tableView, (cellWidth * 3) - 2, 1, Qt.LeftButton, Qt.ShiftModifier) + compare(tableView.selectionModel.selectedIndexes.length, 3) + verify(tableView.selectionModel.isSelected(tableView.model.index(0, 0))) + verify(tableView.selectionModel.isSelected(tableView.model.index(0, 1))) + verify(tableView.selectionModel.isSelected(tableView.model.index(0, 2))) + + // A control click should add a new cell to the selection + mouseClick(tableView, 1, (cellHeight * 2) - 1, Qt.LeftButton, Qt.ControlModifier) + compare(tableView.selectionModel.selectedIndexes.length, 4) + verify(tableView.selectionModel.isSelected(tableView.model.index(0, 0))) + verify(tableView.selectionModel.isSelected(tableView.model.index(0, 1))) + verify(tableView.selectionModel.isSelected(tableView.model.index(0, 2))) + verify(tableView.selectionModel.isSelected(tableView.model.index(1, 0))) + + // A shift click should further extend the selection from the last cell selected + mouseClick(tableView, (cellWidth * 3) - 2, (cellHeight * 2) - 1, Qt.LeftButton, Qt.ShiftModifier) + compare(tableView.selectionModel.selectedIndexes.length, 6) + for (let r = 0; r < 2; ++r) + for (let c = 0; c < 3; ++c) + verify(tableView.selectionModel.isSelected(tableView.model.index(r, c))) + + // Shift click the second selection so that it overlaps with the first + mouseClick(tableView, 1, 1, Qt.LeftButton, Qt.ShiftModifier) + compare(tableView.selectionModel.selectedIndexes.length, 4) + verify(tableView.selectionModel.isSelected(tableView.model.index(0, 0))) + verify(tableView.selectionModel.isSelected(tableView.model.index(0, 1))) + verify(tableView.selectionModel.isSelected(tableView.model.index(0, 2))) + verify(tableView.selectionModel.isSelected(tableView.model.index(1, 0))) + + // Shift click the selection back again. The first selection on + // row 0 should still be present, even if the second selection + // no longer overlaps it. + mouseClick(tableView, (cellWidth * 3) - 2, (cellHeight * 2) - 1, Qt.LeftButton, Qt.ShiftModifier) + compare(tableView.selectionModel.selectedIndexes.length, 6) + for (let r = 0; r < 2; ++r) + for (let c = 0; c < 3; ++c) + verify(tableView.selectionModel.isSelected(tableView.model.index(r, c))) + } + + function test_unselect_click() { + // Check at a ctrl click on top a selected cell + // will cause the cell to be unselected. + let tableView = createTemporaryObject(tableviewComp, testCase) + verify(tableView) + let selectionRectangle = tableView.selectionRectangle + verify(selectionRectangle) + + selectionRectangle.selectionMode = SelectionRectangle.Drag + + // Select some cells + tableView.selectionModel.select(tableView.index(0, 0), ItemSelectionModel.Select) + tableView.selectionModel.select(tableView.index(0, 1), ItemSelectionModel.Select) + tableView.selectionModel.select(tableView.index(0, 3), ItemSelectionModel.Select) + tableView.selectionModel.select(tableView.index(1, 0), ItemSelectionModel.Select) + compare(tableView.selectionModel.selectedIndexes.length, 4) + + // Do a ctrl-click on top of a selected cell. This + // should cause the cell to be unselected. + mouseClick(tableView, cellWidth / 2, cellHeight / 2, Qt.LeftButton, Qt.ControlModifier) + compare(tableView.selectionModel.selectedIndexes.length, 3) + verify(!tableView.selectionModel.isSelected(tableView.model.index(0, 0))) + verify(tableView.selectionModel.isSelected(tableView.model.index(0, 1))) + verify(tableView.selectionModel.isSelected(tableView.model.index(0, 3))) + verify(tableView.selectionModel.isSelected(tableView.model.index(1, 0))) + } + + function test_unselect_drag() { + // Check at a ctrl drag on top a selected cell + // will cause the dragged-over cells to be unselected. + let tableView = createTemporaryObject(tableviewComp, testCase) + verify(tableView) + let selectionRectangle = tableView.selectionRectangle + verify(selectionRectangle) + + selectionRectangle.selectionMode = SelectionRectangle.Drag + + // Select some cells + tableView.selectionModel.select(tableView.index(0, 0), ItemSelectionModel.Select) + tableView.selectionModel.select(tableView.index(0, 1), ItemSelectionModel.Select) + tableView.selectionModel.select(tableView.index(0, 3), ItemSelectionModel.Select) + tableView.selectionModel.select(tableView.index(1, 0), ItemSelectionModel.Select) + compare(tableView.selectionModel.selectedIndexes.length, 4) + + // Do a ctrl-drag on top of the selected cells. This + // should cause all the cells to be unselected. + mousePress(tableView.contentItem, cellWidth / 2, cellHeight / 2, Qt.LeftButton, Qt.ControlModifier) + mouseMove(tableView.contentItem, cellWidth * 4, cellHeight * 2, 0, Qt.LeftButton, Qt.ControlModifier) + compare(tableView.selectionModel.selectedIndexes.length, 0) + + // Move the mouse back to cell 2, and release the mouse. Only + // the top left cells will then be unselected + mouseMove(tableView.contentItem, (cellWidth * 2) - 1, (cellHeight * 2) - 1, 0, Qt.LeftButton, Qt.ControlModifier) + mouseRelease(tableView.contentItem, (cellWidth * 2) - 1, (cellHeight * 2) - 1, Qt.LeftButton, Qt.ControlModifier) + compare(tableView.selectionModel.selectedIndexes.length, 1) + verify(tableView.selectionModel.isSelected(tableView.model.index(0, 3))) } function test_handle_position() { @@ -320,6 +590,43 @@ TestCase { verify(!bottomRightHandle.visible) } + function test_delegateWithTapHandler() { + // Check that we clear the current selection if you start a new + // mouse drag selection on top of a delegate with a tap handler. + let tableView = createTemporaryObject(tableviewComp, testCase) + verify(tableView) + + tableView.delegate = delegateWithTapHandlerComp; + let selectionRectangle = tableView.selectionRectangle + verify(selectionRectangle) + + selectionRectangle.selectionMode = SelectionRectangle.Drag + tableView.selectionMode = TableView.ExtendedSelection + + verify(waitForItemPolished(tableView)) + + let item0_0 = tableView.itemAtIndex(tableView.index(0, 0)) + let item1_1 = tableView.itemAtIndex(tableView.index(1, 1)) + verify(item0_0) + verify(item1_1) + + tableView.selectionModel.select(tableView.index(0, 0), ItemSelectionModel.Select) + compare(tableView.selectionModel.selectedIndexes.length, 1) + compare(tableView.selectionModel.selectedIndexes[0], tableView.index(0, 0)) + + // A drag should clear the current selection and select a new cell + mouseDrag(tableView.contentItem, item1_1.x, item1_1.y, 10, 10, Qt.LeftButton) + compare(tableView.selectionModel.selectedIndexes.length, 1) + compare(tableView.selectionModel.selectedIndexes[0], tableView.index(1, 1)) + + // Verify that a PressAndHold works as well + selectionRectangle.selectionMode = SelectionRectangle.PressAndHold + mousePress(tableView, item0_0.x, item0_0.y, Qt.LeftButton) + mouseRelease(tableView, item0_0.x, item0_0.y, Qt.LeftButton, Qt.NoModifier, 2000) + compare(tableView.selectionModel.selectedIndexes.length, 1) + compare(tableView.selectionModel.selectedIndexes[0], tableView.index(0, 0)) + } + // TODO: enable this test when mouseDrag sends modifiers for all mouse events // (including mouseMove) // function test_multi_selection() { @@ -337,8 +644,8 @@ TestCase { // verify(tableView.selectionModel.isSelected(tableView.model.index(0, 0))) // verify(tableView.selectionModel.isSelected(tableView.model.index(0, 1))) -// // Hold down shift, and drag again to do a multi-selection -// mouseDrag(tableView, 1, cellHeight + 5, (cellWidth * 2) - 2, 1, Qt.LeftButton, Qt.ShiftModifier) +// // Hold down control, and drag again to do a multi-selection +// mouseDrag(tableView, 1, cellHeight + 5, (cellWidth * 2) - 2, 1, Qt.LeftButton, Qt.ControlModifier) // verify(tableView.selectionModel.hasSelection) // compare(tableView.selectionModel.selectedIndexes.length, 4) // verify(tableView.selectionModel.isSelected(tableView.model.index(0, 0))) @@ -375,7 +682,7 @@ TestCase { verify(!tableView.selectionModel.hasSelection) // Do a press and hold mousePress(tableView, 1, 1, Qt.LeftButton) - mousePress(tableView, 1, 1, Qt.LeftButton, Qt.NoModifier, 1000) + mouseRelease(tableView, 1, 1, Qt.LeftButton, Qt.NoModifier, 1000) verify(tableView.selectionModel.hasSelection) compare(tableView.selectionModel.selectedIndexes.length, 1) verify(tableView.selectionModel.isSelected(tableView.model.index(0, 0))) @@ -384,7 +691,7 @@ TestCase { compare(activeSpy.count, 1) // Remove selection - mouseClick(tableView, 1, 1, Qt.LeftButton) + mouseClick(tableView, 100, 100, Qt.LeftButton) verify(!tableView.selectionModel.hasSelection) compare(draggingSpy.count, 0) compare(activeSpy.count, 2) @@ -394,6 +701,31 @@ TestCase { verify(!tableView.selectionModel.hasSelection) } + function test_pressAndHoldPlussShift() { + let tableView = createTemporaryObject(tableviewComp, testCase) + verify(tableView) + let selectionRectangle = tableView.selectionRectangle + verify(selectionRectangle) + + selectionRectangle.selectionMode = SelectionRectangle.Drag + + verify(!tableView.selectionModel.hasSelection) + verify(!tableView.selectionModel.currentIndex.isValid) + + // select cell 0,0 + mouseClick(tableView, 1, 1, Qt.LeftButton) + compare(tableView.selectionModel.currentIndex, tableView.index(0, 0)) + + // do a long press on cell 1,0 while holding down Shift. This will + // select both cells. + mousePress(tableView, cellWidth + 1, 1, Qt.LeftButton, Qt.ShiftModifier) + mouseRelease(tableView, cellWidth + 1, 1, Qt.LeftButton, Qt.ShiftModifier, 2000) + verify(tableView.selectionModel.hasSelection) + compare(tableView.selectionModel.selectedIndexes.length, 2) + verify(tableView.selectionModel.isSelected(tableView.model.index(0, 0))) + verify(tableView.selectionModel.isSelected(tableView.model.index(0, 1))) + } + function test_pressAndHold_on_top_of_handle() { let tableView = createTemporaryObject(tableviewComp, testCase) verify(tableView) @@ -439,8 +771,8 @@ TestCase { // Select four cells in the middle mouseDrag(tableView, cellWidth + 1, cellHeight + 1, (cellWidth * 2) - 2, (cellHeight * 2) - 2, Qt.LeftButton) compare(tableView.selectionModel.selectedIndexes.length, 4) - for (var x = 1; x < 3; ++x) { - for (var y = 1; y < 3; ++y) { + for (let x = 1; x < 3; ++x) { + for (let y = 1; y < 3; ++y) { verify(tableView.selectionModel.isSelected(tableView.model.index(x, y))) } } @@ -448,8 +780,8 @@ TestCase { // Drag on the top left handle, so that the selection extends to cell 0, 0 mouseDrag(tableView, cellWidth, cellHeight, -cellWidth / 2, -cellHeight / 2, Qt.LeftButton) compare(tableView.selectionModel.selectedIndexes.length, 9) - for (x = 0; x < 3; ++x) { - for (y = 0; y < 3; ++y) { + for (let x = 0; x < 3; ++x) { + for (let y = 0; y < 3; ++y) { verify(tableView.selectionModel.isSelected(tableView.model.index(x, y))) } } @@ -467,8 +799,8 @@ TestCase { // Select four cells in the middle mouseDrag(tableView, cellWidth + 1, cellHeight + 1, (cellWidth * 2) - 2, (cellHeight * 2) - 2, Qt.LeftButton) compare(tableView.selectionModel.selectedIndexes.length, 4) - for (var x = 1; x < 3; ++x) { - for (var y = 1; y < 3; ++y) { + for (let x = 1; x < 3; ++x) { + for (let y = 1; y < 3; ++y) { verify(tableView.selectionModel.isSelected(tableView.model.index(x, y))) } } @@ -491,8 +823,8 @@ TestCase { // Select four cells in the middle mouseDrag(tableView, cellWidth + 1, cellHeight + 1, (cellWidth * 2) - 2, (cellHeight * 2) - 2, Qt.LeftButton) compare(tableView.selectionModel.selectedIndexes.length, 4) - for (var x = 1; x < 3; ++x) { - for (var y = 1; y < 3; ++y) { + for (let x = 1; x < 3; ++x) { + for (let y = 1; y < 3; ++y) { verify(tableView.selectionModel.isSelected(tableView.model.index(x, y))) } } @@ -500,11 +832,59 @@ TestCase { // Drag on the bottom right handle, so that the selection expands to cell 9 cells mouseDrag(tableView, cellWidth * 3, cellHeight * 3, 10, 10, Qt.LeftButton) compare(tableView.selectionModel.selectedIndexes.length, 9) - for (x = 1; x < 4; ++x) { - for (y = 1; y < 4; ++y) { + for (let x = 1; x < 4; ++x) { + for (let y = 1; y < 4; ++y) { verify(tableView.selectionModel.isSelected(tableView.model.index(x, y))) } } } + function test_programmatic_unselect() { + // Check that the SelectionRectangle will be deactivated if the + // selection is changed programatically. + let tableView = createTemporaryObject(tableviewComp, testCase) + verify(tableView) + let selectionRectangle = tableView.selectionRectangle + verify(selectionRectangle) + + selectionRectangle.selectionMode = SelectionRectangle.Drag + + verify(!tableView.selectionModel.hasSelection) + mouseDrag(tableView, 1, 1, (cellWidth * 2) - 2, 1, Qt.LeftButton) + compare(tableView.selectionModel.selectedIndexes.length, 2) + verify(selectionRectangle.active) + + tableView.selectionModel.clearSelection() + verify(!selectionRectangle.active) + } + + function test_extend_using_keyboard() { + // Check that the bottom-right selection handle will move if an + // acitve selection is extended with the keyboard + let tableView = createTemporaryObject(tableviewComp, testCase) + verify(tableView) + let selectionRectangle = tableView.selectionRectangle + verify(selectionRectangle) + + selectionRectangle.bottomRightHandle = bottomRightHandleComp + selectionRectangle.selectionMode = SelectionRectangle.Drag + + tableView.forceActiveFocus() + verify(!tableView.selectionModel.hasSelection) + mouseDrag(tableView, 1, 1, (cellWidth * 2) - 2, 1, Qt.LeftButton) + compare(tableView.selectionModel.selectedIndexes.length, 2) + verify(selectionRectangle.active) + verify(bottomRightHandle) + compare(bottomRightHandle.x, (cellWidth * 2) - (bottomRightHandle.width / 2)) + compare(bottomRightHandle.y, cellHeight - (bottomRightHandle.height / 2)) + + keyPress(Qt.Key_Down, Qt.ShiftModifier) + keyRelease(Qt.Key_Down, Qt.ShiftModifier) + keyPress(Qt.Key_Right, Qt.ShiftModifier) + keyRelease(Qt.Key_Right, Qt.ShiftModifier) + verify(selectionRectangle.active) + compare(tableView.selectionModel.selectedIndexes.length, 6) + compare(bottomRightHandle.x, (cellWidth * 3) - (bottomRightHandle.width / 2)) + compare(bottomRightHandle.y, (cellHeight * 2) - (bottomRightHandle.height / 2)) + } } diff --git a/tests/auto/quickcontrols/controls/data/tst_slider.qml b/tests/auto/quickcontrols/controls/data/tst_slider.qml index df3eb71ae2..991d513122 100644 --- a/tests/auto/quickcontrols/controls/data/tst_slider.qml +++ b/tests/auto/quickcontrols/controls/data/tst_slider.qml @@ -1,5 +1,5 @@ // Copyright (C) 2017 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only import QtQuick import QtTest @@ -23,10 +23,12 @@ TestCase { Slider { } } - function test_defaults() { + function init() { failOnWarning(/.?/) + } - var control = createTemporaryObject(slider, testCase) + function test_defaults() { + let control = createTemporaryObject(slider, testCase) verify(control) compare(control.stepSize, 0) @@ -37,7 +39,7 @@ TestCase { } function test_value() { - var control = createTemporaryObject(slider, testCase) + let control = createTemporaryObject(slider, testCase) verify(control) compare(control.value, 0.0) @@ -52,7 +54,7 @@ TestCase { } function test_range() { - var control = createTemporaryObject(slider, testCase, {from: 0, to: 100, value: 50}) + let control = createTemporaryObject(slider, testCase, {from: 0, to: 100, value: 50}) verify(control) compare(control.from, 0) @@ -84,7 +86,7 @@ TestCase { } function test_inverted() { - var control = createTemporaryObject(slider, testCase, {from: 1.0, to: -1.0}) + let control = createTemporaryObject(slider, testCase, {from: 1.0, to: -1.0}) verify(control) compare(control.from, 1.0) @@ -106,7 +108,7 @@ TestCase { } function test_position() { - var control = createTemporaryObject(slider, testCase) + let control = createTemporaryObject(slider, testCase) verify(control) compare(control.value, 0.0) @@ -122,7 +124,7 @@ TestCase { } function test_visualPosition() { - var control = createTemporaryObject(slider, testCase) + let control = createTemporaryObject(slider, testCase) verify(control) compare(control.value, 0.0) @@ -154,7 +156,7 @@ TestCase { } function test_orientation() { - var control = createTemporaryObject(slider, testCase) + let control = createTemporaryObject(slider, testCase) verify(control) compare(control.orientation, Qt.Horizontal) @@ -179,16 +181,16 @@ TestCase { } function test_mouse(data) { - var control = createTemporaryObject(slider, testCase, {orientation: data.orientation, live: data.live}) + let control = createTemporaryObject(slider, testCase, {orientation: data.orientation, live: data.live}) verify(control) - var pressedCount = 0 - var movedCount = 0 + let pressedCount = 0 + let movedCount = 0 - var pressedSpy = signalSpy.createObject(control, {target: control, signalName: "pressedChanged"}) + let pressedSpy = signalSpy.createObject(control, {target: control, signalName: "pressedChanged"}) verify(pressedSpy.valid) - var movedSpy = signalSpy.createObject(control, {target: control, signalName: "moved"}) + let movedSpy = signalSpy.createObject(control, {target: control, signalName: "moved"}) verify(movedSpy.valid) mousePress(control, 0, control.height - 1, Qt.LeftButton) @@ -268,19 +270,19 @@ TestCase { } function test_touch(data) { - var control = createTemporaryObject(slider, testCase, {orientation: data.orientation, live: data.live}) + let control = createTemporaryObject(slider, testCase, {orientation: data.orientation, live: data.live}) verify(control) - var pressedCount = 0 - var movedCount = 0 + let pressedCount = 0 + let movedCount = 0 - var pressedSpy = signalSpy.createObject(control, {target: control, signalName: "pressedChanged"}) + let pressedSpy = signalSpy.createObject(control, {target: control, signalName: "pressedChanged"}) verify(pressedSpy.valid) - var movedSpy = signalSpy.createObject(control, {target: control, signalName: "moved"}) + let movedSpy = signalSpy.createObject(control, {target: control, signalName: "moved"}) verify(movedSpy.valid) - var touch = touchEvent(control) + let touch = touchEvent(control) touch.press(0, control, 0, 0).commit() compare(pressedSpy.count, ++pressedCount) compare(movedSpy.count, movedCount) @@ -349,19 +351,19 @@ TestCase { } function test_multiTouch() { - var control1 = createTemporaryObject(slider, testCase, {live: false}) + let control1 = createTemporaryObject(slider, testCase, {live: false}) verify(control1) - var pressedCount1 = 0 - var movedCount1 = 0 + let pressedCount1 = 0 + let movedCount1 = 0 - var pressedSpy1 = signalSpy.createObject(control1, {target: control1, signalName: "pressedChanged"}) + let pressedSpy1 = signalSpy.createObject(control1, {target: control1, signalName: "pressedChanged"}) verify(pressedSpy1.valid) - var movedSpy1 = signalSpy.createObject(control1, {target: control1, signalName: "moved"}) + let movedSpy1 = signalSpy.createObject(control1, {target: control1, signalName: "moved"}) verify(movedSpy1.valid) - var touch = touchEvent(control1) + let touch = touchEvent(control1) touch.press(0, control1, 0, 0).commit().move(0, control1, control1.width, control1.height).commit() compare(pressedSpy1.count, ++pressedCount1) @@ -379,16 +381,16 @@ TestCase { compare(control1.pressed, true) compare(control1.position, 1.0) - var control2 = createTemporaryObject(slider, testCase, {y: control1.height, live: false}) + let control2 = createTemporaryObject(slider, testCase, {y: control1.height, live: false}) verify(control2) - var pressedCount2 = 0 - var movedCount2 = 0 + let pressedCount2 = 0 + let movedCount2 = 0 - var pressedSpy2 = signalSpy.createObject(control2, {target: control2, signalName: "pressedChanged"}) + let pressedSpy2 = signalSpy.createObject(control2, {target: control2, signalName: "pressedChanged"}) verify(pressedSpy2.valid) - var movedSpy2 = signalSpy.createObject(control2, {target: control2, signalName: "moved"}) + let movedSpy2 = signalSpy.createObject(control2, {target: control2, signalName: "moved"}) verify(movedSpy2.valid) // press the second slider @@ -443,25 +445,25 @@ TestCase { } function test_keys(data) { - var control = createTemporaryObject(slider, testCase, {orientation: data.orientation}) + let control = createTemporaryObject(slider, testCase, {orientation: data.orientation}) verify(control) - var pressedCount = 0 - var movedCount = 0 + let pressedCount = 0 + let movedCount = 0 - var pressedSpy = signalSpy.createObject(control, {target: control, signalName: "pressedChanged"}) + let pressedSpy = signalSpy.createObject(control, {target: control, signalName: "pressedChanged"}) verify(pressedSpy.valid) - var movedSpy = signalSpy.createObject(control, {target: control, signalName: "moved"}) + let movedSpy = signalSpy.createObject(control, {target: control, signalName: "moved"}) verify(movedSpy.valid) control.forceActiveFocus() verify(control.activeFocus) - var oldValue = 0.0 + let oldValue = 0.0 control.value = 0.5 - for (var d1 = 1; d1 <= 10; ++d1) { + for (let d1 = 1; d1 <= 10; ++d1) { oldValue = control.value keyPress(data.decrease) compare(control.pressed, true) @@ -478,7 +480,7 @@ TestCase { compare(movedSpy.count, movedCount) } - for (var i1 = 1; i1 <= 20; ++i1) { + for (let i1 = 1; i1 <= 20; ++i1) { oldValue = control.value keyPress(data.increase) compare(control.pressed, true) @@ -497,7 +499,7 @@ TestCase { control.stepSize = 0.25 - for (var d2 = 1; d2 <= 10; ++d2) { + for (let d2 = 1; d2 <= 10; ++d2) { oldValue = control.value keyPress(data.decrease) compare(control.pressed, true) @@ -514,7 +516,7 @@ TestCase { compare(movedSpy.count, movedCount) } - for (var i2 = 1; i2 <= 10; ++i2) { + for (let i2 = 1; i2 <= 10; ++i2) { oldValue = control.value keyPress(data.increase) compare(control.pressed, true) @@ -536,10 +538,10 @@ TestCase { // test with "unbalanced" paddings (left padding != right padding) to ensure // that the slider position calculation is done taking padding into account // ==> the position is _not_ 0.5 in the middle of the control - var control = createTemporaryObject(slider, testCase, {leftPadding: 10, rightPadding: 20, live: false}) + let control = createTemporaryObject(slider, testCase, {leftPadding: 10, rightPadding: 20, live: false}) verify(control) - var pressedSpy = signalSpy.createObject(control, {target: control, signalName: "pressedChanged"}) + let pressedSpy = signalSpy.createObject(control, {target: control, signalName: "pressedChanged"}) verify(pressedSpy.valid) mousePress(control, 0, 0, Qt.LeftButton) @@ -620,12 +622,12 @@ TestCase { { tag: "SnapOnRelease (-1..1)", snapMode: Slider.SnapOnRelease, from: -1, to: 1, values: [0.0, 0.0, -0.8], positions: [immediate ? 0.0 : 0.5, 0.1, 0.1] }, { tag: "SnapOnRelease (1..-1)", snapMode: Slider.SnapOnRelease, from: 1, to: -1, values: [0.0, 0.0, 0.8], positions: [immediate ? 0.0 : 0.5, 0.1, 0.1] }, // Live - { tag: "SnapAlwaysLive", snapMode: Slider.SnapAlways, from: 0, to: 1, value: 0, stepSize: 1, live: true, sliderPos: 0.6, values: [0, 1, 1], positions: [0, 1, 1] }, - { tag: "SnapAlwaysLive", snapMode: Slider.SnapAlways, from: 0, to: 1, value: 0, stepSize: 1, live: true, sliderPos: 0.4, values: [0, 0, 0], positions: [0, 0, 0] }, - { tag: "NoSnapLive", snapMode: Slider.NoSnap, from: 0, to: 1, value: 0, stepSize: 1, live: true, sliderPos: 0.6, values: [0, 1, 1], positions: [0, 0.6, 0.6] }, - { tag: "NoSnapLive", snapMode: Slider.NoSnap, from: 0, to: 1, value: 0, stepSize: 1, live: true, sliderPos: 0.4, values: [0, 0, 0], positions: [0, 0.4, 0.4] }, - { tag: "SnapOnReleaseLive", snapMode: Slider.SnapOnRelease, from: 0, to: 1, value: 0, stepSize: 1, live: true, sliderPos: 0.6, values: [0, 1, 1], positions: [0, 0.6, 1] }, - { tag: "SnapOnReleaseLive", snapMode: Slider.SnapOnRelease, from: 0, to: 1, value: 0, stepSize: 1, live: true, sliderPos: 0.4, values: [0, 0, 0], positions: [0, 0.4, 0] }, + { tag: "SnapAlwaysLive1", snapMode: Slider.SnapAlways, from: 0, to: 1, value: 0, stepSize: 1, live: true, sliderPos: 0.6, values: [0, 1, 1], positions: [0, 1, 1] }, + { tag: "SnapAlwaysLive2", snapMode: Slider.SnapAlways, from: 0, to: 1, value: 0, stepSize: 1, live: true, sliderPos: 0.4, values: [0, 0, 0], positions: [0, 0, 0] }, + { tag: "NoSnapLive1", snapMode: Slider.NoSnap, from: 0, to: 1, value: 0, stepSize: 1, live: true, sliderPos: 0.6, values: [0, 1, 1], positions: [0, 0.6, 0.6] }, + { tag: "NoSnapLive2", snapMode: Slider.NoSnap, from: 0, to: 1, value: 0, stepSize: 1, live: true, sliderPos: 0.4, values: [0, 0, 0], positions: [0, 0.4, 0.4] }, + { tag: "SnapOnReleaseLive1", snapMode: Slider.SnapOnRelease, from: 0, to: 1, value: 0, stepSize: 1, live: true, sliderPos: 0.6, values: [0, 1, 1], positions: [0, 0.6, 1] }, + { tag: "SnapOnReleaseLive2", snapMode: Slider.SnapOnRelease, from: 0, to: 1, value: 0, stepSize: 1, live: true, sliderPos: 0.4, values: [0, 0, 0], positions: [0, 0.4, 0] }, ] } @@ -635,7 +637,7 @@ TestCase { let sliderPos = data.sliderPos !== undefined ? data.sliderPos : 0.1 let fuzz = 0.05 - var control = createTemporaryObject(slider, testCase, {live: live, snapMode: data.snapMode, from: data.from, to: data.to, stepSize: stepSize}) + let control = createTemporaryObject(slider, testCase, {live: live, snapMode: data.snapMode, from: data.from, to: data.to, stepSize: stepSize}) verify(control) // The test assumes there is no drag threshold for neither mouse or touch. @@ -644,7 +646,7 @@ TestCase { // on a very narrow slider, we ensure the same width of all sliders control.width = testCase.width - var touch = useMouse ? null : touchEvent(control) + let touch = useMouse ? null : touchEvent(control) if (useMouse) mousePress(control, calcMousePos(control, 0.0)) @@ -695,11 +697,11 @@ TestCase { } function test_wheel(data) { - var control = createTemporaryObject(slider, testCase, {wheelEnabled: true, orientation: data.orientation}) + let control = createTemporaryObject(slider, testCase, {wheelEnabled: true, orientation: data.orientation}) verify(control) - var movedCount = 0 - var movedSpy = signalSpy.createObject(control, {target: control, signalName: "moved"}) + let movedCount = 0 + let movedSpy = signalSpy.createObject(control, {target: control, signalName: "moved"}) verify(movedSpy.valid) compare(control.value, 0.0) @@ -761,19 +763,19 @@ TestCase { } function test_wheelPropagation(data) { - var mouseArea = createTemporaryObject(mouseAreaComponent, testCase, { width: parent.width, height: parent.height }) + let mouseArea = createTemporaryObject(mouseAreaComponent, testCase, { width: parent.width, height: parent.height }) verify(mouseArea) - var mouseAreaWheelSpy = signalSpy.createObject(mouseArea, { target: mouseArea, signalName: "wheel" }) + let mouseAreaWheelSpy = signalSpy.createObject(mouseArea, { target: mouseArea, signalName: "wheel" }) verify(mouseAreaWheelSpy.valid) - var control = createTemporaryObject(slider, mouseArea, + let control = createTemporaryObject(slider, mouseArea, { wheelEnabled: true, orientation: data.orientation, stepSize: 1 }) verify(control) compare(control.value, 0.0) - var movedCount = 0 - var movedSpy = signalSpy.createObject(control, { target: control, signalName: "moved" }) + let movedCount = 0 + let movedSpy = signalSpy.createObject(control, { target: control, signalName: "moved" }) verify(movedSpy.valid) // Scroll the handle to the edge. @@ -826,7 +828,7 @@ TestCase { } function test_nullHandle() { - var control = createTemporaryObject(slider, testCase) + let control = createTemporaryObject(slider, testCase) verify(control) control.handle = null @@ -839,7 +841,7 @@ TestCase { } function test_touchDragThreshold_data() { - var d1 = 3; var d2 = 7; + let d1 = 3; let d2 = 7; return [ { tag: "horizontal", orientation: Qt.Horizontal, dx1: d1, dy1: 0, dx2: d2, dy2: 0 }, { tag: "vertical", orientation: Qt.Vertical, dx1: 0, dy1: -d1, dx2: 0, dy2: -d2 }, @@ -849,19 +851,19 @@ TestCase { } function test_touchDragThreshold(data) { - var control = createTemporaryObject(slider, testCase, {touchDragThreshold: 10, live: true, orientation: data.orientation, value: 0.5}) + let control = createTemporaryObject(slider, testCase, {touchDragThreshold: 10, live: true, orientation: data.orientation, value: 0.5}) verify(control) compare(control.touchDragThreshold, 10) - var valueChangedCount = 0 - var valueChangedSpy = signalSpy.createObject(control, {target: control, signalName: "touchDragThresholdChanged"}) + let valueChangedCount = 0 + let valueChangedSpy = signalSpy.createObject(control, {target: control, signalName: "touchDragThresholdChanged"}) verify(valueChangedSpy.valid) control.touchDragThreshold = undefined compare(control.touchDragThreshold, -1) // reset to -1 compare(valueChangedSpy.count, ++valueChangedCount) - var t = 5 + let t = 5 control.touchDragThreshold = t compare(control.touchDragThreshold, t) compare(valueChangedSpy.count, ++valueChangedCount) @@ -870,18 +872,18 @@ TestCase { compare(control.touchDragThreshold, t) compare(valueChangedSpy.count, valueChangedCount) - var pressedCount = 0 - var movedCount = 0 + let pressedCount = 0 + let movedCount = 0 - var pressedSpy = signalSpy.createObject(control, {target: control, signalName: "pressedChanged"}) + let pressedSpy = signalSpy.createObject(control, {target: control, signalName: "pressedChanged"}) verify(pressedSpy.valid) - var movedSpy = signalSpy.createObject(control, {target: control, signalName: "moved"}) + let movedSpy = signalSpy.createObject(control, {target: control, signalName: "moved"}) verify(movedSpy.valid) - var touch = touchEvent(control) - var x0 = control.handle.x + control.handle.width * 0.5 - var y0 = control.handle.y + control.handle.height * 0.5 + let touch = touchEvent(control) + let x0 = control.handle.x + control.handle.width * 0.5 + let y0 = control.handle.y + control.handle.height * 0.5 touch.press(0, control, x0, y0).commit() compare(pressedSpy.count, ++pressedCount) compare(movedSpy.count, movedCount) @@ -902,9 +904,20 @@ TestCase { function test_nullTexture() { failOnWarning("No QSGTexture provided from updateSampledImage(). This is wrong.") - var control = createTemporaryObject(slider, testCase, {width: -100}) + let control = createTemporaryObject(slider, testCase, {width: -100}) verify(control) control.visible = true waitForRendering(control) } + + function test_clickFocus() { + let control = createTemporaryObject(slider, testCase) + verify(control) + + mouseClick(control) + if (Qt.platform.os === "osx") + verify(!control.activeFocus) + else + verify(control.activeFocus) + } } diff --git a/tests/auto/quickcontrols/controls/data/tst_spinbox.qml b/tests/auto/quickcontrols/controls/data/tst_spinbox.qml index df30ef4beb..ba27aeed77 100644 --- a/tests/auto/quickcontrols/controls/data/tst_spinbox.qml +++ b/tests/auto/quickcontrols/controls/data/tst_spinbox.qml @@ -1,10 +1,11 @@ // Copyright (C) 2017 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only import QtQuick import QtTest import QtQuick.Controls import QtQuick.Window +import QtQuick.Layouts TestCase { id: testCase @@ -29,10 +30,12 @@ TestCase { MouseArea { } } - function test_defaults() { + function init() { failOnWarning(/.?/) + } - var control = createTemporaryObject(spinBox, testCase) + function test_defaults() { + let control = createTemporaryObject(spinBox, testCase) verify(control) compare(control.from, 0) @@ -47,7 +50,7 @@ TestCase { } function test_value() { - var control = createTemporaryObject(spinBox, testCase) + let control = createTemporaryObject(spinBox, testCase) verify(control) compare(control.value, 0) @@ -62,7 +65,7 @@ TestCase { } function test_range() { - var control = createTemporaryObject(spinBox, testCase, {from: 0, to: 100, value: 50}) + let control = createTemporaryObject(spinBox, testCase, {from: 0, to: 100, value: 50}) verify(control) compare(control.from, 0) @@ -132,7 +135,7 @@ TestCase { } function test_inverted() { - var control = createTemporaryObject(spinBox, testCase, {from: 100, to: -100}) + let control = createTemporaryObject(spinBox, testCase, {from: 100, to: -100}) verify(control) compare(control.from, 100) @@ -169,16 +172,16 @@ TestCase { } function test_mouse(data) { - var control = createTemporaryObject(spinBox, testCase, {value: data.value}) + let control = createTemporaryObject(spinBox, testCase, {value: data.value}) verify(control) - var button = control[data.button] + let button = control[data.button] verify(button) - var pressedSpy = signalSpy.createObject(control, {target: button, signalName: "pressedChanged"}) + let pressedSpy = signalSpy.createObject(control, {target: button, signalName: "pressedChanged"}) verify(pressedSpy.valid) - var valueModifiedSpy = signalSpy.createObject(control, {target: control, signalName: "valueModified"}) + let valueModifiedSpy = signalSpy.createObject(control, {target: control, signalName: "valueModified"}) verify(valueModifiedSpy.valid) mousePress(button.indicator) @@ -209,27 +212,27 @@ TestCase { } function test_keys(data) { - var control = createTemporaryObject(spinBox, testCase, data.properties) + let control = createTemporaryObject(spinBox, testCase, data.properties) verify(control) - var upPressedCount = 0 - var downPressedCount = 0 - var valueModifiedCount = 0 + let upPressedCount = 0 + let downPressedCount = 0 + let valueModifiedCount = 0 - var upPressedSpy = signalSpy.createObject(control, {target: control.up, signalName: "pressedChanged"}) + let upPressedSpy = signalSpy.createObject(control, {target: control.up, signalName: "pressedChanged"}) verify(upPressedSpy.valid) - var downPressedSpy = signalSpy.createObject(control, {target: control.down, signalName: "pressedChanged"}) + let downPressedSpy = signalSpy.createObject(control, {target: control.down, signalName: "pressedChanged"}) verify(downPressedSpy.valid) - var valueModifiedSpy = signalSpy.createObject(control, {target: control, signalName: "valueModified"}) + let valueModifiedSpy = signalSpy.createObject(control, {target: control, signalName: "valueModified"}) verify(valueModifiedSpy.valid) control.forceActiveFocus() verify(control.activeFocus) - for (var u = 0; u < data.upSteps.length; ++u) { - var wasUpEnabled = control.wrap || control.value < control.to + for (let u = 0; u < data.upSteps.length; ++u) { + let wasUpEnabled = control.wrap || control.value < control.to keyPress(Qt.Key_Up) compare(control.up.pressed, wasUpEnabled) compare(control.down.pressed, false) @@ -251,8 +254,8 @@ TestCase { compare(valueModifiedSpy.count, valueModifiedCount) } - for (var d = 0; d < data.downSteps.length; ++d) { - var wasDownEnabled = control.wrap || control.value > control.from + for (let d = 0; d < data.downSteps.length; ++d) { + let wasDownEnabled = control.wrap || control.value > control.from keyPress(Qt.Key_Down) compare(control.down.pressed, wasDownEnabled) compare(control.up.pressed, false) @@ -276,26 +279,26 @@ TestCase { } function test_locale() { - var control = createTemporaryObject(spinBox, testCase) + let control = createTemporaryObject(spinBox, testCase) verify(control) control.locale = Qt.locale("ar_EG") // Arabic, Egypt - var numbers = ["Ù ", "Ù¡", "Ù¢", "Ù£", "Ù¤", "Ù¥", "Ù¦", "Ù§", "Ù¨", "Ù©"] - for (var i = 0; i < 10; ++i) { + let numbers = ["Ù ", "Ù¡", "Ù¢", "Ù£", "Ù¤", "Ù¥", "Ù¦", "Ù§", "Ù¨", "Ù©"] + for (let i = 0; i < 10; ++i) { control.value = i compare(control.contentItem.text, numbers[i]) } } function test_baseline() { - var control = createTemporaryObject(spinBox, testCase) + let control = createTemporaryObject(spinBox, testCase) verify(control) compare(control.baselineOffset, control.contentItem.y + control.contentItem.baselineOffset) } function test_focus() { - var control = createTemporaryObject(spinBox, testCase, {from: 10, to: 1000, value: 100, focus: true}) + let control = createTemporaryObject(spinBox, testCase, {from: 10, to: 1000, value: 100, focus: true}) verify(control) control.forceActiveFocus() @@ -314,41 +317,465 @@ TestCase { } function test_initialFocus() { - var window = testCase.Window.window + let window = testCase.Window.window verify(window) compare(window.activeFocusItem, window.contentItem) - var control = createTemporaryObject(spinBox, testCase, { editable: true, focus: true }) + let control = createTemporaryObject(spinBox, testCase, { editable: true, focus: true }) verify(control) tryCompare(control.contentItem, "activeFocus", true) } function test_editable() { - var control = createTemporaryObject(spinBox, testCase) + let control = createTemporaryObject(spinBox, testCase) verify(control) - var valueModifiedSpy = signalSpy.createObject(control, {target: control, signalName: "valueModified"}) + let valueModifiedSpy = signalSpy.createObject(control, {target: control, signalName: "valueModified"}) verify(valueModifiedSpy.valid) + let displayTextChangedSpy = signalSpy.createObject(control, {target: control, signalName: "displayTextChanged"}) + verify(displayTextChangedSpy.valid) + + + control.from = 0 + control.to = 10 + compare(control.from, 0) + compare(control.to, 10) + control.contentItem.forceActiveFocus() compare(control.contentItem.activeFocus, true) compare(control.editable, false) control.contentItem.selectAll() + compare(control.displayText, "0") keyClick(Qt.Key_5) keyClick(Qt.Key_Return) + compare(control.displayText, "0") compare(control.value, 0) compare(valueModifiedSpy.count, 0) control.editable = true compare(control.editable, true) control.contentItem.selectAll() + keyClick(Qt.Key_Backspace) keyClick(Qt.Key_5) + compare(control.displayText, "5") keyClick(Qt.Key_Return) compare(control.value, 5) compare(valueModifiedSpy.count, 1) + compare(displayTextChangedSpy.count, 2) + + keyClick(Qt.Key_0) + compare(control.displayText, "50") + compare(control.value, 5) + compare(valueModifiedSpy.count, 1) + compare(displayTextChangedSpy.count, 3) + keyClick(Qt.Key_Return) //will set the value to maximum = 10 + compare(control.displayText, "10") + compare(control.value, 10) + compare(valueModifiedSpy.count, 2) // 0->5->10 + compare(displayTextChangedSpy.count, 4) //0->5->50->10 } + + function test_editable_liveUpdate() { + let control = createTemporaryObject(spinBox, testCase) + verify(control) + + let valueModifiedSpy = signalSpy.createObject(control, {target: control, signalName: "valueModified"}) + verify(valueModifiedSpy.valid) + + let valueChangedSpy = signalSpy.createObject(control, {target: control, signalName: "valueChanged"}) + verify(valueChangedSpy.valid) + + let displayTextChangedSpy = signalSpy.createObject(control, {target: control, signalName: "displayTextChanged"}) + verify(displayTextChangedSpy.valid) + + control.contentItem.forceActiveFocus() + compare(control.contentItem.activeFocus, true) + + control.editable = true + control.live = true + control.from = -10 + control.to = 10 + compare(control.editable, true) + compare(control.live, true) + compare(control.from, -10) + compare(control.to, 10) + + control.contentItem.selectAll() + keyClick(Qt.Key_5) + compare(control.displayText, "5") + compare(control.value, 5) + compare(valueModifiedSpy.count, 0) + compare(valueChangedSpy.count, 1) + compare(displayTextChangedSpy.count, 1) + + keyClick(Qt.Key_0) + compare(control.displayText, "50") // do not set the value + compare(control.value, 5) // if it is out of bounds + compare(valueModifiedSpy.count, 0) + compare(valueChangedSpy.count, 1) + compare(displayTextChangedSpy.count, 2) + + + keyClick(Qt.Key_Backspace) + compare(control.displayText, "5") + compare(control.value, 5) + compare(valueModifiedSpy.count, 0) + compare(valueChangedSpy.count, 1) + compare(displayTextChangedSpy.count, 3) + + keyClick(Qt.Key_Backspace) + compare(control.displayText, "0") + compare(control.value, 0) + compare(valueModifiedSpy.count, 0) + compare(valueChangedSpy.count, 2) + compare(displayTextChangedSpy.count, 4) + + keyClick(Qt.Key_Backspace) + compare(control.displayText, "") + compare(control.value, 0) + compare(valueModifiedSpy.count, 0) + compare(valueChangedSpy.count, 2) + compare(displayTextChangedSpy.count, 5) + } + + Component { + id: doubleBox + SpinBox { + id: doubleSpinBox + locale: Qt.locale("en_US") + + property int decimals: 2 + property double realValue: value / 10**decimals + validator: DoubleValidator { + bottom: Math.min(doubleSpinBox.from, doubleSpinBox.to) + top: Math.max(doubleSpinBox.from, doubleSpinBox.to) + decimals: doubleSpinBox.decimals + notation: DoubleValidator.StandardNotation + locale: doubleSpinBox.locale.name + } + + textFromValue: function(value, locale) { + let res = Number(value / 10**doubleSpinBox.decimals).toLocaleString(locale, 'f', doubleSpinBox.decimals) + return res + } + + valueFromText: function(text, locale) { + let res = Math.round(Number.fromLocaleString(locale, text) * 10**doubleSpinBox.decimals) + return res + } + + onDisplayTextChanged: { + displayTextChangedWithArg(doubleSpinBox.displayText); + } + + signal displayTextChangedWithArg(text: string) + } + } + + function test_editable_doubleSpinBox() { + let control = createTemporaryObject(doubleBox, testCase) + verify(control) + + control.editable = true + control.from = 0 + control.to = 1000000 + control.value = 500 + control.stepSize = 1 + + compare(control.editable, true) + compare(control.from, 0) + compare(control.to, 1000000) + compare(control.value, 500) + compare(control.realValue, 5.00) + compare(control.displayText, "5.00") + + let valueModifiedSpy = signalSpy.createObject(control, {target: control, signalName: "valueModified"}) + verify(valueModifiedSpy.valid) + + let valueChangedSpy = signalSpy.createObject(control, {target: control, signalName: "valueChanged"}) + verify(valueChangedSpy.valid) + + let displayTextChangedSpy = signalSpy.createObject(control, {target: control, signalName: "displayTextChangedWithArg"}) + verify(displayTextChangedSpy.valid) + + control.contentItem.forceActiveFocus() + compare(control.contentItem.activeFocus, true) + + control.contentItem.selectAll() + compare(displayTextChangedSpy.count, 0) + keyClick(Qt.Key_4) + compare(control.value, 500) + compare(control.realValue, 5.00) + compare(control.displayText, "4") + compare(valueModifiedSpy.count, 0) + compare(valueChangedSpy.count, 0) + compare(displayTextChangedSpy.signalArguments[0][0], "4") + compare(displayTextChangedSpy.count, 1) + + keyClick(Qt.Key_Enter) + compare(control.value, 400) + compare(control.realValue, 4.00) + compare(control.displayText, "4.00") + compare(valueModifiedSpy.count, 1) + compare(valueChangedSpy.count, 1) + compare(displayTextChangedSpy.signalArguments[1][0], "4.00") + compare(displayTextChangedSpy.count, 2) + + keyClick(Qt.Key_Backspace) + compare(control.value, 400) + compare(control.realValue, 4.00) + compare(control.displayText, "4.0") + compare(valueModifiedSpy.count, 1) + compare(valueChangedSpy.count, 1) + compare(displayTextChangedSpy.signalArguments[2][0], "4.0") + compare(displayTextChangedSpy.count, 3) + + keyClick(Qt.Key_Backspace) + compare(control.value, 400) + compare(control.realValue, 4.00) + compare(control.displayText, "4") //The fixup removes the trailing "." + compare(valueModifiedSpy.count, 1) + compare(valueChangedSpy.count, 1) + compare(displayTextChangedSpy.signalArguments[3][0], "4") + compare(displayTextChangedSpy.count, 4) + + keyClick(Qt.Key_0) + compare(control.value, 400) + compare(control.realValue, 4.00) + compare(control.displayText, "40") + compare(valueModifiedSpy.count, 1) + compare(valueChangedSpy.count, 1) + compare(displayTextChangedSpy.signalArguments[4][0], "40") + compare(displayTextChangedSpy.count, 5) + + keyClick(Qt.Key_0) + compare(control.value, 400) + compare(control.realValue, 4.00) + compare(control.displayText, "400") + compare(valueModifiedSpy.count, 1) + compare(valueChangedSpy.count, 1) + compare(displayTextChangedSpy.signalArguments[5][0], "400") + compare(displayTextChangedSpy.count, 6) + + keyClick(Qt.Key_0) + compare(control.value, 400) + compare(control.realValue, 4.00) + compare(control.displayText, "4,000") + compare(valueModifiedSpy.count, 1) + compare(valueChangedSpy.count, 1) + compare(displayTextChangedSpy.signalArguments[6][0], "4,000") + compare(displayTextChangedSpy.count, 7) + + keyClick(Qt.Key_Enter) + compare(control.value, 400000) + compare(control.realValue, 4000.00) + compare(control.displayText, "4,000.00") + compare(valueModifiedSpy.count, 2) + compare(valueChangedSpy.count, 2) + compare(displayTextChangedSpy.signalArguments[7][0], "4,000.00") + compare(displayTextChangedSpy.count, 8) + + // Changing to and testing live mode + control.live = true + compare(control.live, true) + + keyClick(Qt.Key_Backspace) + compare(control.value, 400000) + compare(control.realValue, 4000.00) + compare(control.displayText, "4,000.0") + compare(valueModifiedSpy.count, 2) + compare(valueChangedSpy.count, 2) + compare(displayTextChangedSpy.signalArguments[8][0], "4,000.0") + compare(displayTextChangedSpy.count, 9) + + keyClick(Qt.Key_Backspace) + compare(control.value, 400000) + compare(control.realValue, 4000.00) + compare(control.displayText, "4,000") //The fixup removes the trailing "." + compare(valueModifiedSpy.count, 2) + compare(valueChangedSpy.count, 2) + compare(displayTextChangedSpy.signalArguments[9][0], "4,000") + compare(displayTextChangedSpy.count, 10) + + keyClick(Qt.Key_Backspace) + compare(control.displayText, "400.00") + compare(control.value, 40000) + compare(control.realValue, 400.00) + compare(valueModifiedSpy.count, 2) + compare(valueChangedSpy.count, 3) + compare(displayTextChangedSpy.signalArguments[10][0], "400.00") + compare(displayTextChangedSpy.count, 11) + + // It is a bit unfortunate that we need 3 Backspace to go from + // 400 to 4000 on live editing mode. Maybe think about a fix in + // the future to make it more user friendly + keyClick(Qt.Key_Backspace) + keyClick(Qt.Key_Backspace) + keyClick(Qt.Key_Backspace) + compare(control.displayText, "40.00") + compare(control.value, 4000) + compare(control.realValue, 40.00) + compare(valueModifiedSpy.count, 2) + compare(valueChangedSpy.count, 4) + compare(displayTextChangedSpy.signalArguments[11][0], "400.0") + compare(displayTextChangedSpy.signalArguments[12][0], "400") + compare(displayTextChangedSpy.signalArguments[13][0], "40.00") + compare(displayTextChangedSpy.count, 14) + + keyClick(Qt.Key_Backspace) + keyClick(Qt.Key_Backspace) + keyClick(Qt.Key_Backspace) + compare(control.displayText, "4.00") + compare(control.value, 400) + compare(control.realValue, 4.00) + compare(valueModifiedSpy.count, 2) + compare(valueChangedSpy.count, 5) + compare(displayTextChangedSpy.signalArguments[14][0], "40.0") + compare(displayTextChangedSpy.signalArguments[15][0], "40") + compare(displayTextChangedSpy.signalArguments[16][0], "4.00") + compare(displayTextChangedSpy.count, 17) + + keyClick(Qt.Key_Backspace) + keyClick(Qt.Key_Backspace) + keyClick(Qt.Key_1) + compare(control.displayText, "41.00") + compare(control.value, 4100) + compare(control.realValue, 41.00) + compare(valueModifiedSpy.count, 2) + compare(valueChangedSpy.count, 6) + compare(displayTextChangedSpy.signalArguments[17][0], "4.0") + compare(displayTextChangedSpy.signalArguments[18][0], "4") + compare(displayTextChangedSpy.signalArguments[19][0], "41.00") + compare(displayTextChangedSpy.count, 20) + } + + function test_groupSeparatorHandling_data() { + return [ + { tag: "en_EN" }, + { tag: "de_DE" } + ] + } + + function test_groupSeparatorHandling(data) { + let control = createTemporaryObject(spinBox, testCase) + verify(control) + + let testLoc = Qt.locale(data.tag) + control.locale = testLoc + + control.contentItem.forceActiveFocus() + compare(control.contentItem.activeFocus, true) + + control.editable = true + control.live = true + control.from = 0 + control.to = 10*1000*1000 + compare(control.editable, true) + compare(control.live, true) + compare(control.from, 0) + compare(control.to, 10*1000*1000) + + control.contentItem.selectAll() + keyClick(Qt.Key_5) + compare(control.displayText, "5") + compare(control.value, 5) + + let i = 50 + for (; i < 1e7; i*=10) { + keyClick(Qt.Key_0) + compare(control.displayText, testLoc.toString(i)) + compare(control.value, i) + } + + i /= 100; + for (; i > 10; i/=10) { + keyClick(Qt.Key_Backspace) + compare(control.displayText, testLoc.toString(i)) + compare(control.value, i) + } + } + + function test_qtbug64151() { + // Slightly modified example from QTBUG-64151. We use displayText + // instead of contentItem.text as a workaround. + let control = createTemporaryObject(spinBox, testCase) + verify(control) + + control.locale = Qt.locale("en_EN") + + control.from = 0 + control.to = 2000 + control.value = 2000 + control.editable = true + + compare(control.displayText, "2,000") + + control.contentItem.forceActiveFocus() + compare(control.contentItem.activeFocus, true) + keyClick(Qt.Key_Backspace) + keyClick(Qt.Key_Return) + + compare(control.displayText, "200") + compare(control.valueFromText(control.contentItem.text, control.locale), 200) + compare(control.value, 200) + + control.contentItem.forceActiveFocus() + keyClick(Qt.Key_0) + keyClick(Qt.Key_Return) + compare(control.displayText, "2,000") + } + + Component { + id: spinBoxAndAction + RowLayout { + id: layout + property alias spinbox: theSpinbox + property alias button: theButton + SpinBox { + id: theSpinbox + from: 0 + to: 200 + value: 200 + editable: true + live: true + } + + Button { + id: theButton + property int value: 0 + action: Action { + text: "&Do something" + shortcut: "Return" + onTriggered: { + theButton.value = theSpinbox.value; + } + } + } + } + } + + function test_qtbug103205() { + + let control = createTemporaryObject(spinBoxAndAction, testCase) + verify(control) + verify(control.spinbox) + + compare(control.spinbox.displayText, "200") + control.forceActiveFocus() + control.spinbox.forceActiveFocus() + control.spinbox.contentItem.forceActiveFocus() + compare(control.spinbox.contentItem.activeFocus, true) + keyClick(Qt.Key_Backspace) + keyClick(Qt.Key_Return) + + compare(control.spinbox.displayText, "20") + compare(control.button.value, 20) + } + + function test_wheel_data() { return [ { tag: "1", properties: { from: 1, to: 10, value: 1, stepSize: 1 }, upSteps: [2,3,4], downSteps: [3,2,1,1] }, @@ -361,24 +788,24 @@ TestCase { } function test_wheel(data) { - var ma = createTemporaryObject(mouseArea, testCase, {width: 100, height: 100}) + let ma = createTemporaryObject(mouseArea, testCase, {width: 100, height: 100}) verify(ma) data.properties.wheelEnabled = true - var control = spinBox.createObject(ma, data.properties) + let control = spinBox.createObject(ma, data.properties) verify(control) - var valueModifiedCount = 0 - var valueModifiedSpy = signalSpy.createObject(control, {target: control, signalName: "valueModified"}) + let valueModifiedCount = 0 + let valueModifiedSpy = signalSpy.createObject(control, {target: control, signalName: "valueModified"}) verify(valueModifiedSpy.valid) - var delta = 120 + let delta = 120 - var spy = signalSpy.createObject(ma, {target: ma, signalName: "wheel"}) + let spy = signalSpy.createObject(ma, {target: ma, signalName: "wheel"}) verify(spy.valid) - for (var u = 0; u < data.upSteps.length; ++u) { - var wasUpEnabled = control.wrap || control.value < control.to + for (let u = 0; u < data.upSteps.length; ++u) { + let wasUpEnabled = control.wrap || control.value < control.to mouseWheel(control, control.width / 2, control.height / 2, delta, delta) if (wasUpEnabled) ++valueModifiedCount @@ -387,8 +814,8 @@ TestCase { compare(control.value, data.upSteps[u]) } - for (var d = 0; d < data.downSteps.length; ++d) { - var wasDownEnabled = control.wrap || control.value > control.from + for (let d = 0; d < data.downSteps.length; ++d) { + let wasDownEnabled = control.wrap || control.value > control.from mouseWheel(control, control.width / 2, control.height / 2, -delta, -delta) if (wasDownEnabled) ++valueModifiedCount @@ -408,7 +835,7 @@ TestCase { } function test_initiallyDisabledIndicators(data) { - var control = createTemporaryObject(spinBox, testCase, { from: data.from, value: data.value, to: data.to }) + let control = createTemporaryObject(spinBox, testCase, { from: data.from, value: data.value, to: data.to }) verify(control) compare(control.up.indicator.enabled, data.upEnabled) @@ -427,10 +854,10 @@ TestCase { } function test_hover(data) { - var control = createTemporaryObject(spinBox, testCase, {hoverEnabled: data.hoverEnabled, value: data.value}) + let control = createTemporaryObject(spinBox, testCase, {hoverEnabled: data.hoverEnabled, value: data.value}) verify(control) - var button = control[data.button] + let button = control[data.button] compare(control.hovered, false) compare(button.hovered, false) @@ -451,16 +878,16 @@ TestCase { // QTBUG-74688 function test_hoverWhilePressed(data) { - var control = createTemporaryObject(spinBox, testCase, { hoverEnabled: true, value: 50 }) + let control = createTemporaryObject(spinBox, testCase, { hoverEnabled: true, value: 50 }) verify(control) - var button = control[data.tag] + let button = control[data.tag] compare(control.hovered, false) compare(button.hovered, false) // Hover over the indicator. It should be hovered. - var buttonXCenter = button.indicator.x + button.indicator.width / 2 - var buttonYCenter = button.indicator.y + button.indicator.height / 2 + let buttonXCenter = button.indicator.x + button.indicator.width / 2 + let buttonYCenter = button.indicator.y + button.indicator.height / 2 mouseMove(control, buttonXCenter, buttonYCenter) compare(button.hovered, true) @@ -483,13 +910,13 @@ TestCase { } function test_valueFromText(data) { - var control = createTemporaryObject(spinBox, testCase, {editable: data.editable}) + let control = createTemporaryObject(spinBox, testCase, {editable: data.editable}) verify(control) control.forceActiveFocus() verify(control.activeFocus) - var valueFromTextCalls = 0 + let valueFromTextCalls = 0 control.valueFromText = function(text, locale) { ++valueFromTextCalls return Number.fromLocaleString(locale, text); @@ -506,21 +933,21 @@ TestCase { } function test_callDefaultValueFromText() { - var control = createTemporaryObject(spinBox, testCase) + let control = createTemporaryObject(spinBox, testCase) verify(control) compare(control.valueFromText("123", control.locale), 123) } function test_autoRepeat() { - var control = createTemporaryObject(spinBox, testCase) + let control = createTemporaryObject(spinBox, testCase) verify(control) compare(control.value, 0) - var valueSpy = signalSpy.createObject(control, {target: control, signalName: "valueChanged"}) + let valueSpy = signalSpy.createObject(control, {target: control, signalName: "valueChanged"}) verify(valueSpy.valid) - var countBefore = 0 + let countBefore = 0 // repeat up mousePress(control.up.indicator) @@ -572,7 +999,7 @@ TestCase { } function test_initialValue() { - var control = createTemporaryObject(spinBox, testCase, {from: 1000, to: 10000}) + let control = createTemporaryObject(spinBox, testCase, {from: 1000, to: 10000}) verify(control) compare(control.value, 1000) } @@ -594,7 +1021,7 @@ TestCase { } valueFromText: function(text) { - for (var i = 0; i < items.length; ++i) { + for (let i = 0; i < items.length; ++i) { if (items[i].toLowerCase().indexOf(text.toLowerCase()) === 0) return i } @@ -611,10 +1038,10 @@ TestCase { } function test_textFromValue(data) { - var control = createTemporaryObject(data.component, testCase) + let control = createTemporaryObject(data.component, testCase) verify(control) - for (var i = 0; i < data.values.length; ++i) { + for (let i = 0; i < data.values.length; ++i) { control.value = data.values[i] compare(control.value, data.values[i]) compare(control.displayText, data.displayTexts[i]) @@ -622,7 +1049,7 @@ TestCase { } function test_callDefaultTextFromValue() { - var control = createTemporaryObject(spinBox, testCase) + let control = createTemporaryObject(spinBox, testCase) verify(control) compare(control.textFromValue(123, control.locale), "123") } @@ -638,7 +1065,7 @@ TestCase { } function test_indicatorOverridden() { - var control = createTemporaryObject(overriddenSpinBox, testCase) + let control = createTemporaryObject(overriddenSpinBox, testCase) verify(control) compare(control.up.indicator.s, "this is the one"); } @@ -659,9 +1086,8 @@ TestCase { } function test_indicatorOverriddenWithIds() { - var control = createTemporaryObject(overriddenSpinBoxWithIds, testCase) + let control = createTemporaryObject(overriddenSpinBoxWithIds, testCase) verify(control) - // TODO: Use failOnWarning() here when it has been implemented // Specifying an id will result in both the default indicator implementations // and the custom ones being created, but it shouldn't result in any TypeErrors. compare(control.up.indicator.s, "up"); @@ -670,7 +1096,7 @@ TestCase { function test_valueEnterFromOutsideRange() { // Check that changing from 2 to 99 goes to 98 then changing to 99 puts it back to 98 - var control = createTemporaryObject(spinBox, testCase, {from: 2, to: 98, value: 2, editable: true}) + let control = createTemporaryObject(spinBox, testCase, {from: 2, to: 98, value: 2, editable: true}) verify(control) control.forceActiveFocus() @@ -692,4 +1118,39 @@ TestCase { compare(control.displayText, "98") compare(control.contentItem.text, "98") } + + function test_pressedBeforeIncrementOrDecrement(data) { + let control = createTemporaryObject(spinBox, testCase, {from: -8, to: 8, value: 0}) + verify(control) + + control.forceActiveFocus() + verify(control.activeFocus) + + // up, down + control.stepSize = Qt.binding(() => control.up.pressed ? 2 : 1) + keyClick(Qt.Key_Up) // +2 + compare(control.value, 2) + mouseClick(control.up.indicator) // +2 + compare(control.value, 4) + keyClick(Qt.Key_Down) // -1 + compare(control.value, 3) + mouseClick(control.down.indicator) // -1 + compare(control.value, 2) + + // down, up + control.stepSize = Qt.binding(() => control.down.pressed ? 2 : 1) + keyClick(Qt.Key_Down) // -2 + compare(control.value, 0) + mouseClick(control.down.indicator) // -2 + compare(control.value, -2) + keyClick(Qt.Key_Up) // +1 + compare(control.value, -1) + mouseClick(control.up.indicator) // +1 + compare(control.value, 0) + } + + function test_nullValidator() { + let control = createTemporaryObject(spinBox, testCase, { validator: null }) + verify(control) + } } diff --git a/tests/auto/quickcontrols/controls/data/tst_splitview.qml b/tests/auto/quickcontrols/controls/data/tst_splitview.qml index 4cefd834cb..aed303689a 100644 --- a/tests/auto/quickcontrols/controls/data/tst_splitview.qml +++ b/tests/auto/quickcontrols/controls/data/tst_splitview.qml @@ -1,5 +1,5 @@ // Copyright (C) 2022 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only import QtCore import QtQuick @@ -24,9 +24,9 @@ TestCase { } function findHandles(splitView) { - var handles = [] - for (var i = 0; i < splitView.children.length; ++i) { - var child = splitView.children[i] + let handles = [] + for (let i = 0; i < splitView.children.length; ++i) { + let child = splitView.children[i] if (child.objectName.toLowerCase().indexOf("handle") !== -1) handles.push(child) } @@ -42,14 +42,14 @@ TestCase { compare(control.count, Math.floor(expectedGeometries.length / 2) + 1, "Mismatch in actual vs expected number of split items" + context) - var handles = findHandles(control) + let handles = findHandles(control) compare(handles.length, Math.floor(expectedGeometries.length / 2), "Mismatch in actual vs expected number of handle items" + context) - for (var i = 0, splitItemIndex = 0, handleItemIndex = 0; i < expectedGeometries.length; ++i) { - var item = null - var itemType = "" - var typeSpecificIndex = -1 + for (let i = 0, splitItemIndex = 0, handleItemIndex = 0; i < expectedGeometries.length; ++i) { + let item = null + let itemType = "" + let typeSpecificIndex = -1 if (i % 2 == 0) { item = control.itemAt(splitItemIndex) itemType = "split item" @@ -64,7 +64,7 @@ TestCase { verify(item, itemType + " at index " + typeSpecificIndex + " should not be null" + context) - var expectedGeometry = expectedGeometries[i] + let expectedGeometry = expectedGeometries[i] if (expectedGeometry.hasOwnProperty("hidden")) { // It's geometry doesn't matter because it's hidden. verify(!item.visible, itemType + " at index " + typeSpecificIndex + " should be hidden" + context) @@ -74,20 +74,19 @@ TestCase { // Note that the indices mentioned here account for handles; they do not // match the indices reported by QQuickSplitView's logging categories. compare(item.x, expectedGeometry.x, "Mismatch in actual vs expected x value of " - + itemType + " at index " + typeSpecificIndex + context) + + itemType + " " + item + " at index " + typeSpecificIndex + context) compare(item.y, expectedGeometry.y, "Mismatch in actual vs expected y value of " - + itemType + " at index " + typeSpecificIndex + context) + + itemType + " " + item + " at index " + typeSpecificIndex + context) compare(item.width, expectedGeometry.width, "Mismatch in actual vs expected width value of " - + itemType + " at index " + typeSpecificIndex + context) + + itemType + " " + item + " at index " + typeSpecificIndex + context) compare(item.height, expectedGeometry.height, "Mismatch in actual vs expected height value of " - + itemType + " at index " + typeSpecificIndex + context) + + itemType + " " + item + " at index " + typeSpecificIndex + context) } } property real defaultHorizontalHandleWidth: 10 property real defaultVerticalHandleHeight: 10 - Component { id: signalSpyComponent SignalSpy {} @@ -96,14 +95,14 @@ TestCase { Component { id: handleComponent Rectangle { - objectName: "handle" + objectName: `handle ${x},${y} ${width}x${height} visible: ${visible}` implicitWidth: defaultHorizontalHandleWidth implicitHeight: defaultVerticalHandleHeight color: "#444" Text { - objectName: "handleText_" + text - text: parent.x + "," + parent.y + " " + parent.width + "x" + parent.height + objectName: text + "_Text" + text: parent.objectName color: "white" anchors.centerIn: parent rotation: 90 @@ -132,18 +131,20 @@ TestCase { Rectangle {} } - function test_defaults() { + function init() { failOnWarning(/.?/) + } + function test_defaults() { let control = createTemporaryObject(defaultSplitView, testCase) verify(control) } function test_addItemsAfterCompletion() { - var control = createTemporaryObject(splitViewComponent, testCase) + let control = createTemporaryObject(splitViewComponent, testCase) verify(control) - var item0 = rectangleComponent.createObject(control, { implicitWidth: 25, color: "salmon" }) + let item0 = rectangleComponent.createObject(control, { implicitWidth: 25, color: "salmon" }) verify(item0) verify(isPolishScheduled(control)) verify(waitForItemPolished(control)) @@ -153,7 +154,7 @@ TestCase { compare(item0.width, testCase.width) compare(item0.height, testCase.height) - var item1 = rectangleComponent.createObject(control, { implicitWidth: 25, color: "steelblue" }) + let item1 = rectangleComponent.createObject(control, { implicitWidth: 25, color: "steelblue" }) verify(item1) verify(isPolishScheduled(control)) verify(waitForItemPolished(control)) @@ -162,8 +163,8 @@ TestCase { compare(item0.y, 0) compare(item0.width, item0.implicitWidth) compare(item0.height, testCase.height) - var handles = findHandles(control) - var handle0 = handles[0] + let handles = findHandles(control) + let handle0 = handles[0] compare(handle0.x, item0.implicitWidth) compare(handle0.y, 0) compare(handle0.width, defaultHorizontalHandleWidth) @@ -175,10 +176,10 @@ TestCase { } function test_addItemsWithNoSizeAfterCompletion() { - var control = createTemporaryObject(splitViewComponent, testCase) + let control = createTemporaryObject(splitViewComponent, testCase) verify(control) - var item0 = rectangleComponent.createObject(control, { color: "salmon" }) + let item0 = rectangleComponent.createObject(control, { color: "salmon" }) verify(item0) verify(isPolishScheduled(control)) verify(waitForItemPolished(control)) @@ -187,7 +188,7 @@ TestCase { compare(item0.width, testCase.width) compare(item0.height, testCase.height) - var item1 = rectangleComponent.createObject(control, { color: "steelblue" }) + let item1 = rectangleComponent.createObject(control, { color: "steelblue" }) verify(item1) verify(isPolishScheduled(control)) verify(waitForItemPolished(control)) @@ -195,8 +196,8 @@ TestCase { compare(item0.y, 0) compare(item0.width, 0) compare(item0.height, testCase.height) - var handles = findHandles(control) - var handle0 = handles[0] + let handles = findHandles(control) + let handle0 = handles[0] compare(handle0.x, 0) compare(handle0.y, 0) compare(handle0.width, defaultHorizontalHandleWidth) @@ -230,35 +231,35 @@ TestCase { } function test_changeAttachedPropertiesAfterCompletion() { - var control = createTemporaryObject(threeZeroSizedItemsComponent, testCase) + let control = createTemporaryObject(threeZeroSizedItemsComponent, testCase) verify(control) - var item0 = control.itemAt(0) + let item0 = control.itemAt(0) compare(item0.x, 0) compare(item0.y, 0) compare(item0.width, 0) compare(item0.height, testCase.height) - var handles = findHandles(control) - var handle0 = handles[0] + let handles = findHandles(control) + let handle0 = handles[0] compare(handle0.x, 0) compare(handle0.y, 0) compare(handle0.width, defaultHorizontalHandleWidth) compare(handle0.height, testCase.height) - var item1 = control.itemAt(1) + let item1 = control.itemAt(1) compare(item1.x, defaultHorizontalHandleWidth) compare(item1.y, 0) compare(item1.width, 0) compare(item1.height, testCase.height) - var handle1 = handles[1] + let handle1 = handles[1] compare(handle1.x, defaultHorizontalHandleWidth) compare(handle1.y, 0) compare(handle1.width, defaultHorizontalHandleWidth) compare(handle1.height, testCase.height) - var item2 = control.itemAt(2) + let item2 = control.itemAt(2) compare(item2.x, defaultHorizontalHandleWidth * 2) compare(item2.y, 0) compare(item2.width, testCase.width - item2.x) @@ -396,19 +397,19 @@ TestCase { } function test_useAttachedPropertiesIncorrectly_data() { - var properties = [ "fillWidth", "fillHeight", "minimumWidth", "minimumHeight", + let properties = [ "fillWidth", "fillHeight", "minimumWidth", "minimumHeight", "preferredWidth", "preferredHeight", "maximumWidth", "maximumHeight" ] - var data = [] + let data = [] - for (var i = 0; i < properties.length; ++i) { - var property = properties[i] + for (let i = 0; i < properties.length; ++i) { + let property = properties[i] data.push({ tag: "Item," + property, component: itemComponent, property: property, expectedWarning: /.*SplitView: attached properties must be accessed through a direct child of SplitView/ }) } - for (i = 0; i < properties.length; ++i) { - property = properties[i] + for (let i = 0; i < properties.length; ++i) { + let property = properties[i] data.push({ tag: "QtObject," + property, component: objectComponent, property: property, expectedWarning: /.*SplitView: attached properties can only be used on Items/ }) } @@ -418,7 +419,7 @@ TestCase { function test_useAttachedPropertiesIncorrectly(data) { // The object (whatever it may be) is not managed by a SplitView. - var object = createTemporaryObject(data.component, testCase, { objectName: data.tag }) + let object = createTemporaryObject(data.component, testCase, { objectName: data.tag }) verify(object) ignoreWarning(data.expectedWarning) @@ -427,12 +428,11 @@ TestCase { } function test_sizes_data() { - var splitViewWidth = testCase.width - var splitViewHeight = testCase.height - var data = [ + let splitViewWidth = testCase.width + let splitViewHeight = testCase.height + let data = [ { - // When the combined size of items is too large, the non-fill items should just exceed - // the size of the SplitView, exactly as they would were they in a RowLayout, for example. + // When the combined size of items is too large, make them fit. tag: "fillItemOnLeft", expectedGeometries: [ // We're the fill item, but since the combined implicitWidths @@ -445,8 +445,8 @@ TestCase { // Second handle. { x: 200 + defaultHorizontalHandleWidth, y: 0, width: defaultHorizontalHandleWidth, height: splitViewHeight }, - // The third item also gets its implicitWidth. - { x: 200 + defaultHorizontalHandleWidth * 2, y: 0, width: 200, height: splitViewHeight } + // The third item is reduced from its implicitWidth to fit into SplitView. + { x: 200 + defaultHorizontalHandleWidth * 2, y: 0, width: 200 - 2 * defaultHorizontalHandleWidth, height: splitViewHeight } ] }, { @@ -463,8 +463,8 @@ TestCase { // Second handle. { x: 0, y: 200 + defaultVerticalHandleHeight, width: splitViewWidth, height: defaultVerticalHandleHeight }, - // The third item also gets its implicitHeight. - { x: 0, y: 200 + defaultVerticalHandleHeight * 2, width: splitViewWidth, height: 200 } + // The third item is reduced from its implicitWidth to fit into SplitView. + { x: 0, y: 200 + defaultVerticalHandleHeight * 2, width: splitViewWidth, height: 200 - 2 * defaultVerticalHandleHeight } ] }, { @@ -489,9 +489,9 @@ TestCase { } function test_sizes(data) { - var component = Qt.createComponent("splitview/" + data.tag + ".qml") + let component = Qt.createComponent("splitview/" + data.tag + ".qml") compare(component.status, Component.Ready, component.errorString()); - var control = createTemporaryObject(component, testCase, { "handle": handleComponent }) + let control = createTemporaryObject(component, testCase, { "handle": handleComponent }) verify(control) compareSizes(control, data.expectedGeometries) @@ -526,9 +526,9 @@ TestCase { } function test_resetAttachedProperties_data() { - var splitViewWidth = testCase.width - var splitViewHeight = testCase.height - var data = [ + let splitViewWidth = testCase.width + let splitViewHeight = testCase.height + let data = [ { tag: "resetMinimumWidth", orientation: Qt.Horizontal, @@ -696,11 +696,11 @@ TestCase { } function test_resetAttachedProperties(data) { - var control = createTemporaryObject(threeSizedItemsComponent, testCase, + let control = createTemporaryObject(threeSizedItemsComponent, testCase, { "orientation": data.orientation }) verify(control) - var splitItem = control.itemAt(data.splitItemIndex) + let splitItem = control.itemAt(data.splitItemIndex) splitItem.SplitView[data.propertyName] = data.propertyValue verify(isPolishScheduled(control)) verify(waitForItemPolished(control)) @@ -713,35 +713,35 @@ TestCase { } function test_orientation() { - var control = createTemporaryObject(threeSizedItemsComponent, testCase) + let control = createTemporaryObject(threeSizedItemsComponent, testCase) verify(control) - var item0 = control.itemAt(0) + let item0 = control.itemAt(0) compare(item0.x, 0) compare(item0.y, 0) compare(item0.width, item0.implicitWidth) compare(item0.height, testCase.height) - var handles = findHandles(control) - var handle0 = handles[0] + let handles = findHandles(control) + let handle0 = handles[0] compare(handle0.x, item0.implicitWidth) compare(handle0.y, 0) compare(handle0.width, defaultHorizontalHandleWidth) compare(handle0.height, testCase.height) - var item1 = control.itemAt(1) + let item1 = control.itemAt(1) compare(item1.x, item0.width + defaultHorizontalHandleWidth) compare(item1.y, 0) compare(item1.width, item1.implicitWidth) compare(item1.height, testCase.height) - var handle1 = handles[1] + let handle1 = handles[1] compare(handle1.x, item1.x + item1.width) compare(handle1.y, 0) compare(handle1.width, defaultHorizontalHandleWidth) compare(handle1.height, testCase.height) - var item2 = control.itemAt(2) + let item2 = control.itemAt(2) compare(item2.x, item0.width + item1.width + defaultHorizontalHandleWidth * 2) compare(item2.y, 0) compare(item2.width, testCase.width - item2.x) @@ -775,6 +775,75 @@ TestCase { compare(item2.height, testCase.height - item2.y) } + Component { + id: threeSizedItemsComponentWithDefaultHandle + + SplitView { + anchors.fill: parent + + Rectangle { + objectName: "salmon" + color: objectName + implicitWidth: 25 + implicitHeight: 25 + } + Rectangle { + objectName: "navajowhite" + color: objectName + implicitWidth: 100 + implicitHeight: 100 + } + Rectangle { + objectName: "steelblue" + color: objectName + implicitWidth: 200 + implicitHeight: 200 + } + } + } + + function test_orientationWithDefaultHandle() { + const control = createTemporaryObject(threeSizedItemsComponentWithDefaultHandle, testCase) + verify(control) + + const item0 = control.itemAt(0) + compare(item0.x, 0) + compare(item0.y, 0) + compare(item0.width, item0.implicitWidth) + compare(item0.height, testCase.height) + + const item1 = control.itemAt(1) + let handleDefaultWidth = item1.x - item0.width // Find default handle width + compare(item1.x, item0.width + handleDefaultWidth) + compare(item1.y, 0) + compare(item1.width, item1.implicitWidth) + compare(item1.height, testCase.height) + + const item2 = control.itemAt(2) + compare(item2.x, item0.width + item1.width + handleDefaultWidth * 2) + compare(item2.y, 0) + compare(item2.width, testCase.width - item2.x) + compare(item2.height, testCase.height) + + control.orientation = Qt.Vertical + verify(isPolishScheduled(control)) + verify(waitForItemPolished(control)) + compare(item0.x, 0) + compare(item0.y, 0) + compare(item0.width, testCase.width) + compare(item0.height, item0.implicitHeight) + + compare(item1.x, 0) + compare(item1.y, item0.height + handleDefaultWidth) + compare(item1.width, testCase.width) + compare(item1.height, item1.implicitHeight) + + compare(item2.x, 0) + compare(item2.y, item0.height + item1.height + handleDefaultWidth * 2) + compare(item2.width, testCase.width) + compare(item2.height, testCase.height - item2.y) + } + readonly property int splitViewMargins: 50 Component { @@ -876,9 +945,9 @@ TestCase { } function test_dragHandle_data() { - var splitViewWidth = testCase.width - splitViewMargins * 2 - var splitViewHeight = testCase.height - splitViewMargins * 2 - var data = [ + let splitViewWidth = testCase.width - splitViewMargins * 2 + let splitViewHeight = testCase.height - splitViewMargins * 2 + let data = [ { tag: "fillThirdItemAndDragFirstHandlePastRightSide", component: threeSizedItemsComponent, @@ -1034,7 +1103,7 @@ TestCase { { x: 0, y: 0, width: defaultHorizontalHandleWidth, height: splitViewHeight }, { x: defaultHorizontalHandleWidth, y: 0, width: 100, height: splitViewHeight }, { x: 100 + defaultHorizontalHandleWidth, y: 0, width: defaultHorizontalHandleWidth, height: splitViewHeight }, - { x: 100 + defaultHorizontalHandleWidth * 2, y: 0, width: 200, height: splitViewHeight } + { x: 100 + defaultHorizontalHandleWidth * 2, y: 0, width: 200 - defaultHorizontalHandleWidth * 2, height: splitViewHeight } ], expectedGeometriesAfterDrag: [ // The fill item is to the left of the handle at index 1, so the handle belongs @@ -1067,7 +1136,7 @@ TestCase { { x: 0, y: 0, width: splitViewWidth, height: defaultVerticalHandleHeight }, { x: 0, y: defaultVerticalHandleHeight, width: splitViewWidth, height: 100 }, { x: 0, y: 100 + defaultVerticalHandleHeight, width: splitViewWidth, height: defaultVerticalHandleHeight }, - { x: 0, y: 100 + defaultVerticalHandleHeight * 2, width: splitViewWidth, height: 200 } + { x: 0, y: 100 + defaultVerticalHandleHeight * 2, width: splitViewWidth, height: 200 - defaultVerticalHandleHeight * 2 } ], expectedGeometriesAfterDrag: [ // The fill item is to the top of the handle at index 1, so the handle belongs @@ -1099,8 +1168,8 @@ TestCase { { x: defaultHorizontalHandleWidth, y: 0, width: 100, height: splitViewHeight }, { x: 100 + defaultHorizontalHandleWidth, y: 0, width: defaultHorizontalHandleWidth, height: splitViewHeight }, // The second item's implicitWidth is 100, and ours is 200. The available width is 300, - // so both items get their implicit widths. - { x: 100 + defaultHorizontalHandleWidth * 2, y: 0, width: splitViewWidth - 100, height: splitViewHeight } + // so this item gets size 300 - 100 - 2 * 10 = 180. + { x: 100 + defaultHorizontalHandleWidth * 2, y: 0, width: splitViewWidth - 100 - 2 * defaultHorizontalHandleWidth, height: splitViewHeight } ], // Should be unchanged. expectedGeometriesAfterDrag: [ @@ -1108,7 +1177,7 @@ TestCase { { x: 0, y: 0, width: defaultHorizontalHandleWidth, height: splitViewHeight }, { x: defaultHorizontalHandleWidth, y: 0, width: 100, height: splitViewHeight }, { x: 100 + defaultHorizontalHandleWidth, y: 0, width: defaultHorizontalHandleWidth, height: splitViewHeight }, - { x: 100 + defaultHorizontalHandleWidth * 2, y: 0, width: splitViewWidth - 100, height: splitViewHeight } + { x: 100 + defaultHorizontalHandleWidth * 2, y: 0, width: splitViewWidth - 100 - 2 * defaultHorizontalHandleWidth, height: splitViewHeight } ] }, { @@ -1123,7 +1192,9 @@ TestCase { { x: 25, y: 0, width: defaultHorizontalHandleWidth, height: splitViewHeight }, { x: 25 + defaultHorizontalHandleWidth, y: 0, width: 100, height: splitViewHeight }, { x: 25 + 100 + defaultHorizontalHandleWidth, y: 0, width: defaultHorizontalHandleWidth, height: splitViewHeight }, - { x: 25 + 100 + defaultHorizontalHandleWidth * 2, y: 0, width: splitViewWidth - 100, height: splitViewHeight } + // The first item is the filling one, with minimum size 25. Second item is 100. + // The available size is 300, so third item is 300 - 100 - 25 - 2 * 10 = 155. + { x: 25 + 100 + defaultHorizontalHandleWidth * 2, y: 0, width: splitViewWidth - 100 - 25 - 2 * defaultHorizontalHandleWidth, height: splitViewHeight } ], // Should be unchanged. expectedGeometriesAfterDrag: [ @@ -1131,7 +1202,7 @@ TestCase { { x: 25, y: 0, width: defaultHorizontalHandleWidth, height: splitViewHeight }, { x: 25 + defaultHorizontalHandleWidth, y: 0, width: 100, height: splitViewHeight }, { x: 25 + 100 + defaultHorizontalHandleWidth, y: 0, width: defaultHorizontalHandleWidth, height: splitViewHeight }, - { x: 25 + 100 + defaultHorizontalHandleWidth * 2, y: 0, width: splitViewWidth - 100, height: splitViewHeight } + { x: 25 + 100 + defaultHorizontalHandleWidth * 2, y: 0, width: splitViewWidth - 100 - 25 - 2 * defaultHorizontalHandleWidth, height: splitViewHeight } ] }, { @@ -1191,7 +1262,7 @@ TestCase { } function test_dragHandle(data) { - var control = createTemporaryObject(data.component, testCase) + let control = createTemporaryObject(data.component, testCase) verify(control) control.orientation = data.orientation @@ -1199,7 +1270,7 @@ TestCase { // Ensure that there is space to drag outside of the SplitView. control.anchors.margins = splitViewMargins - var fillItem = control.itemAt(data.fillIndex) + let fillItem = control.itemAt(data.fillIndex) if (control.orientation === Qt.Horizontal) fillItem.SplitView.fillWidth = true else @@ -1211,13 +1282,13 @@ TestCase { compareSizes(control, data.expectedGeometriesBeforeDrag, "before drag") // Drag the handle. - var handles = findHandles(control) - var targetHandle = handles[data.handleIndex] + let handles = findHandles(control) + let targetHandle = handles[data.handleIndex] verify(targetHandle.visible) mousePress(targetHandle) verify(control.resizing) // newHandlePos is in scene coordinates, so map it to coordinates local to the handle. - var localPos = testCase.mapToItem(targetHandle, data.newHandlePos.x, data.newHandlePos.y) + let localPos = testCase.mapToItem(targetHandle, data.newHandlePos.x, data.newHandlePos.y) mouseMove(targetHandle, localPos.x - targetHandle.width / 2, localPos.y - targetHandle.height / 2) verify(control.resizing) compareSizes(control, data.expectedGeometriesAfterDrag, "after drag move") @@ -1229,10 +1300,10 @@ TestCase { } function test_splitViewGeometryChanges_data() { - var defaultSplitViewWidth = testCase.width - var defaultSplitViewHeight = testCase.height + let defaultSplitViewWidth = testCase.width + let defaultSplitViewHeight = testCase.height - var data = [ + let data = [ { tag: "growWidth", orientation: Qt.Horizontal, @@ -1296,7 +1367,7 @@ TestCase { } function test_splitViewGeometryChanges(data) { - var control = createTemporaryObject(threeSizedItemsComponent, testCase, + let control = createTemporaryObject(threeSizedItemsComponent, testCase, { "handle": handleComponent, "anchors.fill": undefined, "orientation": data.orientation }) verify(control) @@ -1316,10 +1387,10 @@ TestCase { } function test_splitItemImplicitSizeChanges_data() { - var defaultSplitViewWidth = testCase.width - var defaultSplitViewHeight = testCase.height + let defaultSplitViewWidth = testCase.width + let defaultSplitViewHeight = testCase.height - var data = [ + let data = [ { tag: "growImplicitWidth", orientation: Qt.Horizontal, @@ -1354,11 +1425,11 @@ TestCase { // Tests that implicitWidth/Height changes in items are noticed by SplitView. function test_splitItemImplicitSizeChanges(data) { - var control = createTemporaryObject(threeSizedItemsComponent, testCase, + let control = createTemporaryObject(threeSizedItemsComponent, testCase, { "handle": handleComponent, "orientation": data.orientation }) verify(control) - var firstItem = control.itemAt(0) + let firstItem = control.itemAt(0) if (data.hasOwnProperty("splitItemImplicitWidth")) firstItem.implicitWidth = data.splitItemImplicitWidth @@ -1392,10 +1463,10 @@ TestCase { } function test_handleChanges_data() { - var splitViewWidth = testCase.width - var splitViewHeight = testCase.height + let splitViewWidth = testCase.width + let splitViewHeight = testCase.height - var data = [ + let data = [ { tag: "growHandleWidth", orientation: Qt.Horizontal, @@ -1455,7 +1526,7 @@ TestCase { } function test_handleChanges(data) { - var control = createTemporaryObject(threeSizedItemsComponent, testCase, + let control = createTemporaryObject(threeSizedItemsComponent, testCase, { "orientation": data.orientation }) verify(control) @@ -1466,10 +1537,10 @@ TestCase { } function test_insertRemoveItems_data() { - var splitViewWidth = testCase.width - var splitViewHeight = testCase.height + let splitViewWidth = testCase.width + let splitViewHeight = testCase.height - var data = [ + let data = [ { tag: "insertItemAtHorizontalEnd", orientation: Qt.Horizontal, @@ -1552,17 +1623,17 @@ TestCase { } function test_insertRemoveItems(data) { - var control = createTemporaryObject(threeSizedItemsComponent, testCase, + let control = createTemporaryObject(threeSizedItemsComponent, testCase, { "orientation": data.orientation }) verify(control) if (data.hasOwnProperty("removeItemAtIndex")) { - var itemToRemove = control.itemAt(data.removeItemAtIndex) + let itemToRemove = control.itemAt(data.removeItemAtIndex) verify(itemToRemove) control.removeItem(itemToRemove) } else if (data.hasOwnProperty("insertItemAtIndex")) { - var itemToAdd = smallRectComponent.createObject(control) + let itemToAdd = smallRectComponent.createObject(control) control.insertItem(data.insertItemAtIndex, itemToAdd) } @@ -1572,19 +1643,19 @@ TestCase { } function test_removeAllItems() { - var control = createTemporaryObject(threeSizedItemsComponent, testCase) + let control = createTemporaryObject(threeSizedItemsComponent, testCase) verify(control) while (control.count > 0) - var itemToRemove = control.removeItem(control.itemAt(0)) + control.removeItem(control.itemAt(0)) // Shouldn't crash. } function test_hideItems_data() { - var splitViewWidth = testCase.width - var splitViewHeight = testCase.height + let splitViewWidth = testCase.width + let splitViewHeight = testCase.height - var data = [ + let data = [ { tag: "hideItemAtHorizontalEnd", orientation: Qt.Horizontal, @@ -1655,12 +1726,12 @@ TestCase { } function test_hideItems(data) { - var control = createTemporaryObject(threeSizedItemsComponent, testCase, + let control = createTemporaryObject(threeSizedItemsComponent, testCase, { "orientation": data.orientation }) verify(control) - for (var i = 0; i < data.hideIndices.length; ++i) { - var itemToHide = control.itemAt(data.hideIndices[i]) + for (let i = 0; i < data.hideIndices.length; ++i) { + let itemToHide = control.itemAt(data.hideIndices[i]) verify(itemToHide) itemToHide.visible = false } @@ -1671,10 +1742,10 @@ TestCase { } function test_hideAndShowItems_data() { - var splitViewWidth = testCase.width - var splitViewHeight = testCase.height + let splitViewWidth = testCase.width + let splitViewHeight = testCase.height - var data = [ + let data = [ { tag: "hideLastTwoHorizontalItems", orientation: Qt.Horizontal, @@ -1704,12 +1775,12 @@ TestCase { } function test_hideAndShowItems(data) { - var control = createTemporaryObject(threeSizedItemsComponent, testCase, + let control = createTemporaryObject(threeSizedItemsComponent, testCase, { "orientation": data.orientation }) verify(control) - for (var i = 0; i < data.hideIndices.length; ++i) { - var itemToHide = control.itemAt(data.hideIndices[i]) + for (let i = 0; i < data.hideIndices.length; ++i) { + let itemToHide = control.itemAt(data.hideIndices[i]) verify(itemToHide) itemToHide.visible = false } @@ -1717,8 +1788,8 @@ TestCase { verify(waitForItemPolished(control)) compareSizes(control, data.expectedGeometriesAfterHiding, "after hiding") - for (i = 0; i < data.showIndices.length; ++i) { - var itemToShow = control.itemAt(data.showIndices[i]) + for (let i = 0; i < data.showIndices.length; ++i) { + let itemToShow = control.itemAt(data.showIndices[i]) verify(itemToShow) itemToShow.visible = true } @@ -1728,10 +1799,10 @@ TestCase { } function test_moveHiddenItems_data() { - var splitViewWidth = testCase.width - var splitViewHeight = testCase.height + let splitViewWidth = testCase.width + let splitViewHeight = testCase.height - var data = [ + let data = [ { tag: "hideSecondItemAndMoveItToFirst", orientation: Qt.Horizontal, @@ -1767,12 +1838,12 @@ TestCase { } function test_moveHiddenItems(data) { - var control = createTemporaryObject(threeSizedItemsComponent, testCase, + let control = createTemporaryObject(threeSizedItemsComponent, testCase, { "orientation": data.orientation }) verify(control) - for (var i = 0; i < data.hideIndices.length; ++i) { - var itemToHide = control.itemAt(data.hideIndices[i]) + for (let i = 0; i < data.hideIndices.length; ++i) { + let itemToHide = control.itemAt(data.hideIndices[i]) verify(itemToHide) itemToHide.visible = false } @@ -1782,8 +1853,8 @@ TestCase { verify(waitForItemPolished(control)) compareSizes(control, data.expectedGeometriesAfterMoving, "after moving") - for (i = 0; i < data.showIndices.length; ++i) { - var itemToShow = control.itemAt(data.showIndices[i]) + for (let i = 0; i < data.showIndices.length; ++i) { + let itemToShow = control.itemAt(data.showIndices[i]) verify(itemToShow) itemToShow.visible = true } @@ -1802,10 +1873,10 @@ TestCase { } function test_draggingHandleInFlickable() { - var flickable = createTemporaryObject(flickableComponent, testCase) + let flickable = createTemporaryObject(flickableComponent, testCase) verify(flickable) - var control = threeSizedItemsComponent.createObject(flickable.contentItem) + let control = threeSizedItemsComponent.createObject(flickable.contentItem) verify(control) control.anchors.fill = undefined @@ -1816,19 +1887,19 @@ TestCase { verify(isPolishScheduled(control)) verify(waitForItemPolished(control)) - var contentXSpy = signalSpyComponent.createObject(flickable, + let contentXSpy = signalSpyComponent.createObject(flickable, { target: flickable, signalName: "contentXChanged" }) verify(contentXSpy.valid) - var contentYSpy = signalSpyComponent.createObject(flickable, + let contentYSpy = signalSpyComponent.createObject(flickable, { target: flickable, signalName: "contentYChanged" }) verify(contentYSpy.valid) // Drag the first handle to the right; // the flickable's contentX and contentY shouldn't change. - var firstItem = control.itemAt(0) - var firstItemOriginalWidth = firstItem.width - var handles = findHandles(control) - var firstHandle = handles[0] + let firstItem = control.itemAt(0) + let firstItemOriginalWidth = firstItem.width + let handles = findHandles(control) + let firstHandle = handles[0] // Add some vertical movement in there as well. mouseDrag(firstHandle, firstHandle.width / 2, firstHandle.height / 2, 100, 50) compare(contentXSpy.count, 0) @@ -1839,7 +1910,7 @@ TestCase { control.orientation = Qt.Vertical control.width = control.parent.width - 100 control.height = 400 - var firstItemOriginalHeight = firstItem.height + let firstItemOriginalHeight = firstItem.height verify(isPolishScheduled(control)) verify(waitForItemPolished(control)) @@ -2284,14 +2355,14 @@ TestCase { if ((Qt.platform.pluginName === "offscreen") || (Qt.platform.pluginName === "minimal")) skip("Mouse hovering not functional on offscreen/minimal platforms") - var control = createTemporaryObject(threeSizedItemsComponent, testCase) + let control = createTemporaryObject(threeSizedItemsComponent, testCase) verify(control) control.anchors.margins = 50 - var handles = findHandles(control) - var firstHandle = handles[0] + let handles = findHandles(control) + let firstHandle = handles[0] - var handleCenter = control.mapFromItem(firstHandle, firstHandle.width / 2, firstHandle.height / 2) + let handleCenter = control.mapFromItem(firstHandle, firstHandle.width / 2, firstHandle.height / 2) // Test fails if we don't do two moves for some reason... mouseMove(control, handleCenter.x, handleCenter.y) mouseMove(control, handleCenter.x, handleCenter.y) @@ -2316,15 +2387,15 @@ TestCase { if ((Qt.platform.pluginName === "offscreen") || (Qt.platform.pluginName === "minimal")) skip("Mouse hovering not functional on offscreen/minimal platforms") - var control = createTemporaryObject(threeSizedItemsComponent, testCase) + let control = createTemporaryObject(threeSizedItemsComponent, testCase) verify(control) control.anchors.margins = 50 - var handles = findHandles(control) - var firstHandle = handles[0] + let handles = findHandles(control) + let firstHandle = handles[0] // First, ensure that the handle is hovered + pressed. - var handleCenter = control.mapFromItem(firstHandle, firstHandle.width / 2, firstHandle.height / 2) + let handleCenter = control.mapFromItem(firstHandle, firstHandle.width / 2, firstHandle.height / 2) // Test fails if we don't do two moves for some reason... mouseMove(control, handleCenter.x, handleCenter.y) mouseMove(control, handleCenter.x, handleCenter.y) @@ -2342,8 +2413,8 @@ TestCase { compare(handles.length, 1) // No handles should be hovered/pressed. - for (var i = 0; i < handles.length; ++i) { - var handle = handles[i] + for (let i = 0; i < handles.length; ++i) { + let handle = handles[i] verify(!handle.SplitHandle.hovered, "handle at index " + i + " should not be hovered") verify(!handle.SplitHandle.pressed, "handle at index " + i + " should not be hovered") } @@ -2366,16 +2437,16 @@ TestCase { } function test_saveAndRestoreState(data) { - var control = createTemporaryObject(threeSizedItemsComponent, testCase, { orientation: data.orientation }) + let control = createTemporaryObject(threeSizedItemsComponent, testCase, { orientation: data.orientation }) verify(control) compare(control.orientation, data.orientation) - var lastItem = control.itemAt(2) + let lastItem = control.itemAt(2) verify(lastItem) lastItem.SplitView[data.propertyName] = data.propertyValue // Save the state. - var settings = createTemporaryObject(settingsComponent, testCase) + let settings = createTemporaryObject(settingsComponent, testCase) verify(settings) settings.setValue("splitView", control.saveState()) @@ -2394,11 +2465,11 @@ TestCase { } function test_changePreferredSizeDuringLayout() { - var control = createTemporaryObject(threeSizedItemsComponent, testCase) + let control = createTemporaryObject(threeSizedItemsComponent, testCase) verify(control) - var firstItem = control.itemAt(0) - var secondItem = control.itemAt(1) + let firstItem = control.itemAt(0) + let secondItem = control.itemAt(1) secondItem.widthChanged.connect(function() { if (secondItem.width < 10) firstItem.SplitView.preferredWidth = 50 @@ -2439,28 +2510,31 @@ TestCase { // m_ignoreNextDelayedLayoutRequest doesn't interfere with any action from // the user that results in a delayed layout. function test_changePreferredSizeDuringLayoutWhileDraggingHandle() { - var control = createTemporaryObject(threeSizedItemsComponent, testCase) + let control = createTemporaryObject(threeSizedItemsComponent, testCase) verify(control) - var firstItem = control.itemAt(0) - var secondItem = control.itemAt(1) + let firstItem = control.itemAt(0) + let secondItem = control.itemAt(1) firstItem.widthChanged.connect(function() { if (firstItem.width === 0) secondItem.SplitView.preferredWidth = 50 }) // Start dragging the handle. - var handles = findHandles(control) - var targetHandle = handles[0] + let handles = findHandles(control) + let targetHandle = handles[0] mousePress(targetHandle) verify(control.resizing) - var localPos = testCase.mapToItem(targetHandle, 15, testCase.height / 2) + let localPos = testCase.mapToItem(targetHandle, 15, testCase.height / 2) // Move the handle to the very left, so that the item's width becomes zero. mouseMove(targetHandle, -100, targetHandle.height / 2) verify(control.resizing) compare(firstItem.width, 0) compare(secondItem.SplitView.preferredWidth, 50) + // Wait for polish so item width becomes preferredWidth + verify(isPolishScheduled(control)) + verify(waitForItemPolished(control)) compare(secondItem.width, 50) mouseRelease(targetHandle, -100, targetHandle.height / 2, Qt.LeftButton) verify(!control.resizing) @@ -2476,7 +2550,7 @@ TestCase { // QTBUG-79270 function test_hideSplitViewWithOneItem() { - var control = createTemporaryObject(oneItemComponent, testCase) + let control = createTemporaryObject(oneItemComponent, testCase) verify(control) // Shouldn't be an assertion failure. control.visible = false @@ -2485,7 +2559,7 @@ TestCase { // QTBUG-79302: ensure that the Repeater's items are actually generated. // test_dragHandle:repeater tests dragging behavior with a Repeater. function test_repeater(data) { - var control = createTemporaryObject(repeaterSplitViewComponent, testCase) + let control = createTemporaryObject(repeaterSplitViewComponent, testCase) verify(control) compare(control.repeater.count, 3) compare(control.contentChildren.length, 3) @@ -2515,15 +2589,15 @@ TestCase { if (Qt.platform.pluginName === "offscreen" || Qt.platform.pluginName === "minimal") skip("Mouse hovering not functional on offscreen/minimal platforms") - var control = createTemporaryObject(hoverableChildrenSplitViewComponent, testCase) + let control = createTemporaryObject(hoverableChildrenSplitViewComponent, testCase) verify(control) verify(isPolishScheduled(control)) verify(waitForItemPolished(control)) // Move the mouse over the handle. - var handles = findHandles(control) - var targetHandle = handles[0] + let handles = findHandles(control) + let targetHandle = handles[0] // Test fails if we don't do two moves for some reason... QTBUG-94968 mouseMove(targetHandle, targetHandle.width / 2, targetHandle.height / 2) mouseMove(targetHandle, targetHandle.width / 2, targetHandle.height / 2) @@ -2603,4 +2677,88 @@ TestCase { verify(!firstHandle.SplitHandle.pressed) compare(firstItem.width, 125) } + + Component { + id: hiddenItemComponent + + SplitView { + anchors.fill: parent + handle: handleComponent + orientation: Qt.Horizontal + + component SplitItem: Rectangle { + objectName: labelText + + SplitView.preferredWidth: 50 + SplitView.fillHeight: true + + required property string labelText + + Text { + anchors.fill: parent + wrapMode: Text.Wrap + horizontalAlignment: Text.AlignHCenter + verticalAlignment: Text.AlignVCenter + text: `${parent.labelText} - width: ${parent.width.toFixed(2)}` + } + } + + SplitItem { + color: "blue" + labelText: "View 1" + } + SplitItem { + color: "red" + labelText: "View 2 (hidden)" + visible: false + } + SplitItem { + color: "purple" + labelText: "View 3" + } + SplitItem { + color: "yellow" + labelText: "View 4" + } + } + } + + function test_resizeHiddenItem() { + let control = createTemporaryObject(hiddenItemComponent, testCase) + verify(control) + + const standardItemWidth = 50 + let expectedGeometries = [ + // First item. + { x: 0, y: 0, width: standardItemWidth, height: control.height }, + // First handle. + { x: standardItemWidth, y: 0, width: defaultHorizontalHandleWidth, height: control.height }, + // The second item and its handle are hidden. + { hidden: true }, + { hidden: true }, + // Third item. + { x: standardItemWidth + defaultHorizontalHandleWidth, y: 0, width: standardItemWidth, height: control.height }, + // Third handle. + { x: (standardItemWidth * 2) + defaultHorizontalHandleWidth, y: 0, width: defaultHorizontalHandleWidth, height: control.height }, + // Fourth item. + { x: (standardItemWidth * 2) + (defaultHorizontalHandleWidth * 2), y: 0, + width: control.width - (standardItemWidth * 2) - (defaultHorizontalHandleWidth * 2), height: control.height } + ] + compareSizes(control, expectedGeometries, "before dragging handle") + + // Drag the third handle to the right. + let handles = findHandles(control) + let thirdHandle = handles[2] + // The third (index 4 here) item should get one pixel bigger, and the fourth one pixel smaller. + ++expectedGeometries[4].width + ++expectedGeometries[5].x // handle + ++expectedGeometries[6].x + --expectedGeometries[6].width + // Use individual events rather than mouseDrag because that will move it past the drag threshold, + // which we don't want, since we only want to move by 1 pixel. + mousePress(thirdHandle) + mouseMove(thirdHandle, thirdHandle.width / 2 + 1, thirdHandle.height / 2, 16) + mouseRelease(thirdHandle) + compareSizes(control, expectedGeometries, "after dragging handle") + } } diff --git a/tests/auto/quickcontrols/controls/data/tst_stackview.qml b/tests/auto/quickcontrols/controls/data/tst_stackview.qml index 8584385cbf..7e373c66ff 100644 --- a/tests/auto/quickcontrols/controls/data/tst_stackview.qml +++ b/tests/auto/quickcontrols/controls/data/tst_stackview.qml @@ -1,13 +1,17 @@ // Copyright (C) 2017 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +pragma ComponentBehavior: Bound import QtQuick import QtTest import QtQuick.Controls +import QtQuick.Templates as T import Qt.test.controls TestCase { id: testCase + objectName: name width: 200 height: 200 visible: true @@ -16,10 +20,10 @@ TestCase { Item { id: item } Component { id: textField; TextField { } } - Component { id: component; Item { } } + Component { id: itemComponent; Item { } } Component { - id: stackView + id: stackViewComponent StackView { } } @@ -30,60 +34,62 @@ TestCase { Component { id: withRequired; Item { required property int i }} - function test_defaults() { + function init() { failOnWarning(/.?/) + } - let control = createTemporaryObject(stackView, testCase) + function test_defaults() { + let control = createTemporaryObject(stackViewComponent, testCase) verify(control) } function test_initialItem() { - var control1 = createTemporaryObject(stackView, testCase) + let control1 = createTemporaryObject(stackViewComponent, testCase) verify(control1) compare(control1.currentItem, null) control1.destroy() - var control2 = createTemporaryObject(stackView, testCase, {initialItem: item}) + let control2 = createTemporaryObject(stackViewComponent, testCase, {initialItem: item}) verify(control2) compare(control2.currentItem, item) control2.destroy() - var control3 = createTemporaryObject(stackView, testCase, {initialItem: component}) + let control3 = createTemporaryObject(stackViewComponent, testCase, {initialItem: itemComponent}) verify(control3) verify(control3.currentItem) control3.destroy() } function test_currentItem() { - var control = createTemporaryObject(stackView, testCase, {initialItem: item}) + let control = createTemporaryObject(stackViewComponent, testCase, {initialItem: item}) verify(control) compare(control.currentItem, item) - control.push(component) + control.push(itemComponent) verify(control.currentItem !== item) control.pop(StackView.Immediate) compare(control.currentItem, item) } function test_busy() { - var control = createTemporaryObject(stackView, testCase) + let control = createTemporaryObject(stackViewComponent, testCase) verify(control) compare(control.busy, false) - var busyCount = 0 - var busySpy = signalSpy.createObject(control, {target: control, signalName: "busyChanged"}) + let busyCount = 0 + let busySpy = signalSpy.createObject(control, {target: control, signalName: "busyChanged"}) verify(busySpy.valid) - control.push(component) + control.push(itemComponent) compare(control.busy, false) compare(busySpy.count, busyCount) - control.push(component) + control.push(itemComponent) compare(control.busy, true) compare(busySpy.count, ++busyCount) tryCompare(control, "busy", false) compare(busySpy.count, ++busyCount) - control.replace(component) + control.replace(itemComponent) compare(control.busy, true) compare(busySpy.count, ++busyCount) tryCompare(control, "busy", false) @@ -98,14 +104,14 @@ TestCase { control.pushEnter = null control.pushExit = null - control.push(component) + control.push(itemComponent) compare(control.busy, false) compare(busySpy.count, busyCount) control.replaceEnter = null control.replaceExit = null - control.replace(component) + control.replace(itemComponent) compare(control.busy, false) compare(busySpy.count, busyCount) @@ -118,15 +124,15 @@ TestCase { } function test_status() { - var control = createTemporaryObject(stackView, testCase) + let control = createTemporaryObject(stackViewComponent, testCase) verify(control) - var item1 = component.createObject(control) + let item1 = itemComponent.createObject(control) compare(item1.StackView.status, StackView.Inactive) control.push(item1) compare(item1.StackView.status, StackView.Active) - var item2 = component.createObject(control) + let item2 = itemComponent.createObject(control) compare(item2.StackView.status, StackView.Inactive) control.push(item2) compare(item2.StackView.status, StackView.Activating) @@ -142,15 +148,15 @@ TestCase { } function test_index() { - var control = createTemporaryObject(stackView, testCase) + let control = createTemporaryObject(stackViewComponent, testCase) verify(control) - var item1 = component.createObject(control) + let item1 = itemComponent.createObject(control) compare(item1.StackView.index, -1) control.push(item1, StackView.Immediate) compare(item1.StackView.index, 0) - var item2 = component.createObject(control) + let item2 = itemComponent.createObject(control) compare(item2.StackView.index, -1) control.push(item2, StackView.Immediate) compare(item2.StackView.index, 1) @@ -162,15 +168,15 @@ TestCase { } function test_view() { - var control = createTemporaryObject(stackView, testCase) + let control = createTemporaryObject(stackViewComponent, testCase) verify(control) - var item1 = component.createObject(control) + let item1 = itemComponent.createObject(control) compare(item1.StackView.view, null) control.push(item1, StackView.Immediate) compare(item1.StackView.view, control) - var item2 = component.createObject(control) + let item2 = itemComponent.createObject(control) compare(item2.StackView.view, null) control.push(item2, StackView.Immediate) compare(item2.StackView.view, control) @@ -182,13 +188,13 @@ TestCase { } function test_depth() { - var control = createTemporaryObject(stackView, testCase) + let control = createTemporaryObject(stackViewComponent, testCase) verify(control) - var depthChanges = 0 - var emptyChanges = 0 - var depthSpy = signalSpy.createObject(control, {target: control, signalName: "depthChanged"}) - var emptySpy = signalSpy.createObject(control, {target: control, signalName: "emptyChanged"}) + let depthChanges = 0 + let emptyChanges = 0 + let depthSpy = signalSpy.createObject(control, {target: control, signalName: "depthChanged"}) + let emptySpy = signalSpy.createObject(control, {target: control, signalName: "emptyChanged"}) verify(depthSpy.valid) verify(emptySpy.valid) compare(control.depth, 0) @@ -206,25 +212,25 @@ TestCase { compare(control.empty, true) compare(emptySpy.count, ++emptyChanges) - control.push(component, StackView.Immediate) + control.push(itemComponent, StackView.Immediate) compare(control.depth, 1) compare(depthSpy.count, ++depthChanges) compare(control.empty, false) compare(emptySpy.count, ++emptyChanges) - control.push(component, StackView.Immediate) + control.push(itemComponent, StackView.Immediate) compare(control.depth, 2) compare(depthSpy.count, ++depthChanges) compare(control.empty, false) compare(emptySpy.count, emptyChanges) - control.replace(component, StackView.Immediate) + control.replace(itemComponent, StackView.Immediate) compare(control.depth, 2) compare(depthSpy.count, depthChanges) compare(control.empty, false) compare(emptySpy.count, emptyChanges) - control.replace([component, component], StackView.Immediate) + control.replace([itemComponent, itemComponent], StackView.Immediate) compare(control.depth, 3) compare(depthSpy.count, ++depthChanges) compare(control.empty, false) @@ -253,12 +259,21 @@ TestCase { compare(depthSpy.count, depthChanges) compare(control.empty, true) compare(emptySpy.count, emptyChanges) + + control.push(item, StackView.PushTransition) + compare(depthSpy.count, ++depthChanges) + compare(emptySpy.count, ++emptyChanges) + compare(control.depth, 1) + control.clear(StackView.PopTransition) + compare(depthSpy.count, ++depthChanges) + compare(emptySpy.count, ++emptyChanges) + compare(control.depth, 0) } function test_size() { - var container = createTemporaryObject(component, testCase, {width: 200, height: 200}) + let container = createTemporaryObject(itemComponent, testCase, {width: 200, height: 200}) verify(container) - var control = stackView.createObject(container, {width: 100, height: 100}) + let control = stackViewComponent.createObject(container, {width: 100, height: 100}) verify(control) container.width += 10 @@ -286,7 +301,7 @@ TestCase { compare(item.height, control.height) } - function test_focus_data() { + function test_focus_data() : var { return [ { tag: "true", focus: true, forceActiveFocus: false }, { tag: "false", focus: false, forceActiveFocus: false }, @@ -294,8 +309,8 @@ TestCase { ] } - function test_focus(data) { - var control = createTemporaryObject(stackView, testCase, {initialItem: item, width: 200, height: 200}) + function test_focus(data: var) { + let control = createTemporaryObject(stackViewComponent, testCase, {initialItem: item, width: 200, height: 200}) verify(control) if (data.focus) @@ -304,7 +319,7 @@ TestCase { control.forceActiveFocus() compare(control.activeFocus, data.focus || data.forceActiveFocus) - var page = control.push(textField, StackView.Immediate) + let page = control.push(textField, StackView.Immediate) verify(page) compare(control.currentItem, page) compare(page.activeFocus, control.activeFocus) @@ -316,12 +331,12 @@ TestCase { } function test_find() { - var control = createTemporaryObject(stackView, testCase) + let control = createTemporaryObject(stackViewComponent, testCase) verify(control) - var item1 = component.createObject(control, {objectName: "1"}) - var item2 = component.createObject(control, {objectName: "2"}) - var item3 = component.createObject(control, {objectName: "3"}) + let item1 = itemComponent.createObject(control, {objectName: "1"}) + let item2 = itemComponent.createObject(control, {objectName: "2"}) + let item3 = itemComponent.createObject(control, {objectName: "3"}) control.push(item1, StackView.Immediate) control.push(item2, StackView.Immediate) @@ -341,10 +356,10 @@ TestCase { } function test_get() { - var control = createTemporaryObject(stackView, testCase) + let control = createTemporaryObject(stackViewComponent, testCase) verify(control) - control.push([item, component, component], StackView.Immediate) + control.push([item, itemComponent, itemComponent], StackView.Immediate) verify(control.get(0, StackView.DontLoad)) compare(control.get(0, StackView.ForceLoad), item) @@ -355,8 +370,10 @@ TestCase { verify(control.get(2, StackView.ForceLoad)) } + property bool qmlProperty + function test_push() { - var control = createTemporaryObject(stackView, testCase) + let control = createTemporaryObject(stackViewComponent, testCase) verify(control) // missing arguments @@ -372,58 +389,163 @@ TestCase { control.push(Qt.createQmlObject('import QtQml; QtObject { }', control)) // push(item) - var item1 = component.createObject(control, {objectName:"1"}) + let item1 = itemComponent.createObject(control, {objectName:"1"}) compare(control.push(item1, StackView.Immediate), item1) compare(control.depth, 1) compare(control.currentItem, item1) // push([item]) - var item2 = component.createObject(control, {objectName:"2"}) + let item2 = itemComponent.createObject(control, {objectName:"2"}) compare(control.push([item2], StackView.Immediate), item2) compare(control.depth, 2) compare(control.currentItem, item2) // push(item, {properties}) - var item3 = component.createObject(control) + let item3 = itemComponent.createObject(control) compare(control.push(item3, {objectName:"3"}, StackView.Immediate), item3) compare(item3.objectName, "3") compare(control.depth, 3) compare(control.currentItem, item3) // push([item, {properties}]) - var item4 = component.createObject(control) + let item4 = itemComponent.createObject(control) compare(control.push([item4, {objectName:"4"}], StackView.Immediate), item4) compare(item4.objectName, "4") compare(control.depth, 4) compare(control.currentItem, item4) // push(component, {properties}) - var item5 = control.push(component, {objectName:"5"}, StackView.Immediate) + let item5 = control.push(itemComponent, {objectName:"5"}, StackView.Immediate) compare(item5.objectName, "5") compare(control.depth, 5) compare(control.currentItem, item5) // push([component, {properties}]) - var item6 = control.push([component, {objectName:"6"}], StackView.Immediate) + let item6 = control.push([itemComponent, {objectName:"6"}], StackView.Immediate) compare(item6.objectName, "6") compare(control.depth, 6) compare(control.currentItem, item6) + + // push([component, {binding}]) - with JS variable in binding + let jsVariable = false + let item7 = control.push([itemComponent, {objectName: Qt.binding(() => { + return jsVariable.toString() })}], StackView.Immediate) + compare(item7.objectName, "false") + compare(control.depth, 7) + compare(control.currentItem, item7) + jsVariable = true + expectFailContinue("", "QTBUG-114959") + compare(item7.objectName, "true") + + // push([component, {binding}]) - with QML property in binding + qmlProperty = false + let item8 = control.push([itemComponent, {objectName: Qt.binding(() => { + return testCase.qmlProperty.toString() })}], StackView.Immediate) + compare(item8.objectName, "false") + compare(control.depth, 8) + compare(control.currentItem, item8) + qmlProperty = true + compare(item8.objectName, "true") + } + + function test_pushNew() { + let control = createTemporaryObject(stackViewComponent, testCase) + verify(control) + + // Passing the wrong type to a strongly-typed function results in an exception. + let exceptionThrown = false + try { + ignoreWarning(/Could not convert argument 0 at/) + const stackTraceLineCount = 5 + for (let i = 0; i < stackTraceLineCount; ++i) + ignoreWarning(/.*@.*qml/) + control.pushItem(Qt.createQmlObject('import QtQml; QtObject { }', control)) + } catch (e) { + exceptionThrown = true + } + verify(exceptionThrown) + compare(control.depth, 0) + + // pushItem(item) + let item1 = itemComponent.createObject(control, {objectName:"1"}) + compare(control.pushItem(item1, {}, StackView.Immediate), item1) + compare(control.depth, 1) + compare(control.currentItem, item1) + + // pushItems([item]) + let item2 = itemComponent.createObject(control, {objectName:"2"}) + compare(control.pushItems([item2], StackView.Immediate), item2) + compare(control.depth, 2) + compare(control.currentItem, item2) + + // pushItems([item, component, url]) + let item3 = itemComponent.createObject(control) + let actualCurrent = control.pushItems([item3, itemComponent, Qt.resolvedUrl("stackview/Rect.qml")], StackView.Immediate) + let expectedCurrent = control.get(control.depth - 1, StackView.DontLoad) + compare(actualCurrent, expectedCurrent) + compare(control.depth, 5) + compare(control.currentItem, expectedCurrent) + + // pushItems([item, {properties}]) + let item4 = itemComponent.createObject(control) + compare(control.pushItems([item4, {objectName:"4"}], StackView.Immediate), item4) + compare(item4.objectName, "4") + compare(control.depth, 6) + compare(control.currentItem, item4) + + // pushItems([item, {properties}, component, {properties}, url, {properties}]) + let item5 = itemComponent.createObject(control) + let item7 = control.pushItems([ + item5, {objectName: "object5"}, + itemComponent, {objectName: "object6"}, + Qt.resolvedUrl("stackview/Rect.qml"), {objectName: "object7"} + ], + StackView.Immediate) + item5 = control.get(control.depth - 3, StackView.ForceLoad) + let item6 = control.get(control.depth - 2, StackView.ForceLoad) + compare(item7, control.get(control.depth - 1, StackView.ForceLoad)) + compare(item5.objectName, "object5") + compare(item6.objectName, "object6") + compare(item7.objectName, "object7") + compare(control.depth, 9) + compare(control.currentItem, item7) + + // pushItems([component, {binding}]) - with JS variable in binding + let jsVariable = false + let item8 = control.pushItems([itemComponent, {objectName: Qt.binding(() => { + return jsVariable.toString() })}], StackView.Immediate) + compare(item8.objectName, "false") + compare(control.depth, 10) + compare(control.currentItem, item8) + jsVariable = true + expectFailContinue("", "QTBUG-114959") + compare(item8.objectName, "true") + + // pushItems([component, {binding}]) - with QML property in binding + qmlProperty = false + let item9 = control.pushItems([itemComponent, {objectName: Qt.binding(() => { + return testCase.qmlProperty.toString() })}], StackView.Immediate) + compare(item9.objectName, "false") + compare(control.depth, 11) + compare(control.currentItem, item9) + qmlProperty = true + compare(item9.objectName, "true") } // Escape special Regexp characters with a '\' (backslash) prefix so that \a str can be // used as a Regexp pattern. - function escapeRegExp(str) { + function escapeRegExp(str: string): string { // "$&" is the last matched substring return str.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'); } function test_pop() { - var control = createTemporaryObject(stackView, testCase) + let control = createTemporaryObject(stackViewComponent, testCase) verify(control) - var items = [] - for (var i = 0; i < 7; ++i) - items.push(component.createObject(control, {objectName:i})) + let items = [] + for (let i = 0; i < 7; ++i) + items.push(itemComponent.createObject(control, {objectName:i})) control.push(items, StackView.Immediate) @@ -451,7 +573,7 @@ TestCase { compare(control.currentItem, items[2]) // don't pop non-existent item - ignoreWarning(new RegExp(".*QML StackView: pop: unknown argument: " + escapeRegExp(testCase.toString()))) + ignoreWarning(new RegExp(".*QML StackView: pop: can't find item to pop: " + escapeRegExp(testCase.toString()))) compare(control.pop(testCase, StackView.Immediate), null) compare(control.depth, 3) compare(control.currentItem, items[2]) @@ -462,8 +584,75 @@ TestCase { compare(control.currentItem, items[0]) } + function test_popNew() { + let control = createTemporaryObject(stackViewComponent, testCase) + verify(control) + + let items = [] + for (let i = 0; i < 7; ++i) + items.push(itemComponent.createObject(control, {objectName:i})) + + compare(control.pushItems(items, StackView.Immediate), items[6]) + compare(control.depth, 7) + + // pop the top most item + compare(control.popCurrentItem(StackView.Immediate), items[6]) + compare(control.depth, 6) + compare(control.currentItem, items[5]) + + // pop down to the current item (does nothing as it's already the top-most item) + compare(control.popToItem(control.currentItem, StackView.Immediate), null) + compare(control.depth, 6) + compare(control.currentItem, items[5]) + + // pop down to (but not including) the Nth item + compare(control.popToItem(items[3], StackView.Immediate), items[5]) + compare(control.depth, 4) + compare(control.currentItem, items[3]) + + // pop the top most item + compare(control.popCurrentItem(StackView.Immediate), items[3]) + compare(control.depth, 3) + compare(control.currentItem, items[2]) + + // don't pop non-existent item + ignoreWarning(new RegExp(".*QML StackView: pop: can't find item to pop: TestCase.*")) + compare(control.popToItem(testCase, StackView.Immediate), null) + compare(control.depth, 3) + compare(control.currentItem, items[2]) + + // The new functions don't support passing null. + ignoreWarning(new RegExp(".*QML StackView: pop: item cannot be null")) + compare(control.popToItem(null, StackView.Immediate), null) + compare(control.depth, 3) + compare(control.currentItem, items[2]) + + // Test that popToIndex pops down to an Nth item. + control.clear() + compare(control.depth, 0) + + items = [] + for (let i = 0; i < 3; ++i) + items.push(itemComponent.createObject(control, { objectName: i })) + compare(control.pushItems(items, StackView.Immediate), items[2]) + compare(control.depth, 3) + + compare(control.popToIndex(1, StackView.Immediate), items[2]) + compare(control.depth, 2) + + compare(control.popToIndex(0, StackView.Immediate), items[1]) + compare(control.depth, 1) + + // Also check that popCurrentItem still pops when depth is 1, + // because pop() doesn't, and we don't want that behavior with the new function. + compare(control.popCurrentItem(StackView.Immediate), items[0]) + + ignoreWarning(new RegExp(".*QML StackView: pop: no items to pop")) + compare(control.popCurrentItem(StackView.Immediate), null) + } + function test_replace() { - var control = createTemporaryObject(stackView, testCase) + let control = createTemporaryObject(stackViewComponent, testCase) verify(control) // missing arguments @@ -479,71 +668,116 @@ TestCase { compare(control.replace(Qt.createQmlObject('import QtQml; QtObject { }', control)), null) // replace(item) - var item1 = component.createObject(control, {objectName:"1"}) + let item1 = itemComponent.createObject(control, {objectName:"1"}) compare(control.replace(item1, StackView.Immediate), item1) compare(control.depth, 1) compare(control.currentItem, item1) // replace([item]) - var item2 = component.createObject(control, {objectName:"2"}) + let item2 = itemComponent.createObject(control, {objectName:"2"}) compare(control.replace([item2], StackView.Immediate), item2) compare(control.depth, 1) compare(control.currentItem, item2) // replace(item, {properties}) - var item3 = component.createObject(control) + let item3 = itemComponent.createObject(control) compare(control.replace(item3, {objectName:"3"}, StackView.Immediate), item3) compare(item3.objectName, "3") compare(control.depth, 1) compare(control.currentItem, item3) // replace([item, {properties}]) - var item4 = component.createObject(control) + let item4 = itemComponent.createObject(control) compare(control.replace([item4, {objectName:"4"}], StackView.Immediate), item4) compare(item4.objectName, "4") compare(control.depth, 1) compare(control.currentItem, item4) // replace(component, {properties}) - var item5 = control.replace(component, {objectName:"5"}, StackView.Immediate) + let item5 = control.replace(itemComponent, {objectName:"5"}, StackView.Immediate) compare(item5.objectName, "5") compare(control.depth, 1) compare(control.currentItem, item5) // replace([component, {properties}]) - var item6 = control.replace([component, {objectName:"6"}], StackView.Immediate) + let item6 = control.replace([itemComponent, {objectName:"6"}], StackView.Immediate) compare(item6.objectName, "6") compare(control.depth, 1) compare(control.currentItem, item6) // replace the topmost item - control.push(component) + control.push(itemComponent) compare(control.depth, 2) - var item7 = control.replace(control.get(1), component, StackView.Immediate) + let item7 = control.replace(control.get(1), itemComponent, StackView.Immediate) compare(control.depth, 2) compare(control.currentItem, item7) // replace the item in the middle - control.push(component) - control.push(component) - control.push(component) + control.push(itemComponent) + control.push(itemComponent) + control.push(itemComponent) compare(control.depth, 5) - var item8 = control.replace(control.get(2), component, StackView.Immediate) + let item8 = control.replace(control.get(2), itemComponent, StackView.Immediate) compare(control.depth, 3) compare(control.currentItem, item8) } + function test_replaceNew() { + let control = createTemporaryObject(stackViewComponent, testCase) + verify(control) + + // replace(item) - replace currentItem + let item1 = itemComponent.createObject(control, {objectName:"1"}) + compare(control.replaceCurrentItem(item1, {}, StackView.Immediate), item1) + compare(control.depth, 1) + compare(control.currentItem, item1) + + // replace([item]) - replace currentItem + let item2 = itemComponent.createObject(control, {objectName:"2"}) + compare(control.replaceCurrentItem(item2, {}, StackView.Immediate), item2) + compare(control.depth, 1) + compare(control.currentItem, item2) + + // replace(item, {properties}) - replace currentItem + let item3 = itemComponent.createObject(control) + compare(control.replaceCurrentItem(item3, {objectName:"3"}, StackView.Immediate), item3) + compare(item3.objectName, "3") + compare(control.depth, 1) + compare(control.currentItem, item3) + + // replace([item, {properties}]) - replace currentItem + let item4 = itemComponent.createObject(control) + compare(control.replaceCurrentItem([item4, {objectName:"4"}], StackView.Immediate), item4) + compare(item4.objectName, "4") + compare(control.depth, 1) + compare(control.currentItem, item4) + + // replace(component, {properties}) - replace currentItem + let item5 = control.replaceCurrentItem(itemComponent, {objectName:"5"}, StackView.Immediate) + compare(control.currentItem, item5) + compare(item5.objectName, "5") + compare(control.depth, 1) + compare(control.currentItem, item5) + + // replace([component, {properties}]) - replace currentItem + let item6 = control.replaceCurrentItem([itemComponent, {objectName:"6"}], StackView.Immediate) + compare(control.currentItem, item6) + compare(item6.objectName, "6") + compare(control.depth, 1) + compare(control.currentItem, item6) + } + function test_clear() { - var control = createTemporaryObject(stackView, testCase) + let control = createTemporaryObject(stackViewComponent, testCase) verify(control) - control.push(component, StackView.Immediate) + control.push(itemComponent, StackView.Immediate) control.clear() compare(control.depth, 0) compare(control.busy, false) - control.push(component, StackView.Immediate) + control.push(itemComponent, StackView.Immediate) control.clear(StackView.PopTransition) compare(control.depth, 0) @@ -551,22 +785,22 @@ TestCase { tryCompare(control, "busy", false) } - function test_visibility_data() { + function test_visibility_data() : var { return [ {tag:"default transitions", properties: {}}, {tag:"null transitions", properties: {pushEnter: null, pushExit: null, popEnter: null, popExit: null}} ] } - function test_visibility(data) { - var control = createTemporaryObject(stackView, testCase, data.properties) + function test_visibility(data: var) { + let control = createTemporaryObject(stackViewComponent, testCase, data.properties) verify(control) - var item1 = component.createObject(control) + let item1 = itemComponent.createObject(control) control.push(item1, StackView.Immediate) verify(item1.visible) - var item2 = component.createObject(control) + let item2 = itemComponent.createObject(control) control.push(item2) tryCompare(item1, "visible", false) verify(item2.visible) @@ -579,6 +813,7 @@ TestCase { Component { id: transitionView StackView { + id: stackView property int popEnterRuns property int popExitRuns property int pushEnterRuns @@ -587,32 +822,32 @@ TestCase { property int replaceExitRuns popEnter: Transition { PauseAnimation { duration: 1 } - onRunningChanged: if (!running) ++popEnterRuns + onRunningChanged: if (!running) ++stackView.popEnterRuns } popExit: Transition { PauseAnimation { duration: 1 } - onRunningChanged: if (!running) ++popExitRuns + onRunningChanged: if (!running) ++stackView.popExitRuns } pushEnter: Transition { PauseAnimation { duration: 1 } - onRunningChanged: if (!running) ++pushEnterRuns + onRunningChanged: if (!running) ++stackView.pushEnterRuns } pushExit: Transition { PauseAnimation { duration: 1 } - onRunningChanged: if (!running) ++pushExitRuns + onRunningChanged: if (!running) ++stackView.pushExitRuns } replaceEnter: Transition { PauseAnimation { duration: 1 } - onRunningChanged: if (!running) ++replaceEnterRuns + onRunningChanged: if (!running) ++stackView.replaceEnterRuns } replaceExit: Transition { PauseAnimation { duration: 1 } - onRunningChanged: if (!running) ++replaceExitRuns + onRunningChanged: if (!running) ++stackView.replaceExitRuns } } } - function test_transitions_data() { + function test_transitions_data() : var { return [ { tag: "undefined", operation: undefined, pushEnterRuns: [1,2,2,2], pushExitRuns: [0,1,1,1], replaceEnterRuns: [0,0,1,1], replaceExitRuns: [0,0,1,1], popEnterRuns: [0,0,0,1], popExitRuns: [0,0,0,1] }, @@ -627,11 +862,11 @@ TestCase { ] } - function test_transitions(data) { - var control = createTemporaryObject(transitionView, testCase) + function test_transitions(data: var) { + let control = createTemporaryObject(transitionView, testCase) verify(control) - control.push(component, data.operation) + control.push(itemComponent, data.operation) tryCompare(control, "busy", false) compare(control.pushEnterRuns, data.pushEnterRuns[0]) compare(control.pushExitRuns, data.pushExitRuns[0]) @@ -640,7 +875,7 @@ TestCase { compare(control.popEnterRuns, data.popEnterRuns[0]) compare(control.popExitRuns, data.popExitRuns[0]) - control.push(component, data.operation) + control.push(itemComponent, data.operation) tryCompare(control, "busy", false) compare(control.pushEnterRuns, data.pushEnterRuns[1]) compare(control.pushExitRuns, data.pushExitRuns[1]) @@ -649,7 +884,7 @@ TestCase { compare(control.popEnterRuns, data.popEnterRuns[1]) compare(control.popExitRuns, data.popExitRuns[1]) - control.replace(component, data.operation) + control.replace(itemComponent, data.operation) tryCompare(control, "busy", false) compare(control.pushEnterRuns, data.pushEnterRuns[2]) compare(control.pushExitRuns, data.pushExitRuns[2]) @@ -677,7 +912,7 @@ TestCase { TestItem { } } - function test_ownership_data() { + function test_ownership_data() : var { return [ {tag:"item, transition", arg: indestructibleItem, operation: StackView.Transition, destroyed: false}, {tag:"item, immediate", arg: indestructibleItem, operation: StackView.Immediate, destroyed: false}, @@ -688,15 +923,15 @@ TestCase { ] } - function test_ownership(data) { - var control = createTemporaryObject(transitionView, testCase, {initialItem: component}) + function test_ownership(data: var) { + let control = createTemporaryObject(transitionView, testCase, {initialItem: itemComponent}) verify(control) // push-pop control.push(data.arg, StackView.Immediate) verify(control.currentItem) verify(control.currentItem.hasOwnProperty("destroyedCallback")) - var destroyed = false + let destroyed = false control.currentItem.destroyedCallback = function() { destroyed = true } control.pop(data.operation) tryCompare(control, "busy", false) @@ -709,7 +944,7 @@ TestCase { verify(control.currentItem.hasOwnProperty("destroyedCallback")) destroyed = false control.currentItem.destroyedCallback = function() { destroyed = true } - control.replace(component, data.operation) + control.replace(itemComponent, data.operation) tryCompare(control, "busy", false) wait(0) // deferred delete compare(destroyed, data.destroyed) @@ -725,17 +960,17 @@ TestCase { } function test_destroyOnRemoved() { - var control = createTemporaryObject(stackView, testCase, { initialItem: component }) + let control = createTemporaryObject(stackViewComponent, testCase, { initialItem: itemComponent }) verify(control) - var item = removeComponent.createObject(control) + let item = removeComponent.createObject(control) verify(item) - var removedSpy = signalSpy.createObject(control, { target: item.StackView, signalName: "removed" }) + let removedSpy = signalSpy.createObject(control, { target: item.StackView, signalName: "removed" }) verify(removedSpy) verify(removedSpy.valid) - var destructionSpy = signalSpy.createObject(control, { target: item.Component, signalName: "destruction" }) + let destructionSpy = signalSpy.createObject(control, { target: item.Component, signalName: "destruction" }) verify(destructionSpy) verify(destructionSpy.valid) @@ -760,7 +995,7 @@ TestCase { // push-replace control.push(item, StackView.Immediate) compare(control.currentItem, item) - control.replace(component, StackView.Transition) + control.replace(itemComponent, StackView.Transition) item = null tryCompare(removedSpy, "count", 2) tryCompare(destructionSpy, "count", 2) @@ -768,15 +1003,15 @@ TestCase { } function test_pushOnRemoved() { - var control = createTemporaryObject(stackView, testCase, { initialItem: component }) + let control = createTemporaryObject(stackViewComponent, testCase, { initialItem: itemComponent }) verify(control) - var item = control.push(component, StackView.Immediate) + let item = control.push(itemComponent, StackView.Immediate) verify(item) item.StackView.onRemoved.connect(function() { ignoreWarning(/.*QML StackView: cannot push while already in the process of completing a pop/) - control.push(component, StackView.Immediate) + control.push(itemComponent, StackView.Immediate) }) // don't crash (QTBUG-62153) @@ -787,13 +1022,13 @@ TestCase { id: attachedItem Item { property int index: StackView.index - property StackView view: StackView.view + property T.StackView view: StackView.view property int status: StackView.status } } function test_attached() { - var control = createTemporaryObject(stackView, testCase, {initialItem: attachedItem}) + let control = createTemporaryObject(stackViewComponent, testCase, {initialItem: attachedItem}) compare(control.get(0).index, 0) compare(control.get(0).view, control) @@ -825,18 +1060,19 @@ TestCase { } function test_interaction() { - var control = createTemporaryObject(stackView, testCase, {initialItem: testButton, width: testCase.width, height: testCase.height}) + let control = createTemporaryObject(stackViewComponent, testCase, + {initialItem: testButton, width: testCase.width, height: testCase.height}) verify(control) - var firstButton = control.currentItem + let firstButton = control.currentItem verify(firstButton) - var firstClicks = 0 - var secondClicks = 0 - var thirdClicks = 0 + let firstClicks = 0 + let secondClicks = 0 + let thirdClicks = 0 // push - default transition - var secondButton = control.push(testButton) + let secondButton = control.push(testButton) compare(control.busy, true) mouseClick(firstButton) // filtered while busy mouseClick(secondButton) // filtered while busy @@ -847,7 +1083,7 @@ TestCase { compare(secondButton.clicks, ++secondClicks) // replace - default transition - var thirdButton = control.replace(testButton) + let thirdButton = control.replace(testButton) compare(control.busy, true) mouseClick(secondButton) // filtered while busy mouseClick(thirdButton) // filtered while busy @@ -941,10 +1177,11 @@ TestCase { // QTBUG-50305 function test_events() { - var control = createTemporaryObject(stackView, testCase, {initialItem: mouseArea, width: testCase.width, height: testCase.height}) + let control = createTemporaryObject(stackViewComponent, testCase, + {initialItem: mouseArea, width: testCase.width, height: testCase.height}) verify(control) - var testItem = control.currentItem + let testItem = control.currentItem verify(testItem) testItem.doubleClicked.connect(function() { @@ -961,10 +1198,11 @@ TestCase { } function test_ungrab() { - var control = createTemporaryObject(stackView, testCase, {initialItem: mouseArea, width: testCase.width, height: testCase.height}) + let control = createTemporaryObject(stackViewComponent, testCase, + {initialItem: mouseArea, width: testCase.width, height: testCase.height}) verify(control) - var testItem = control.currentItem + let testItem = control.currentItem verify(testItem) mousePress(testItem) @@ -981,7 +1219,7 @@ TestCase { } function test_failures() { - var control = createTemporaryObject(stackView, testCase, {initialItem: component}) + let control = createTemporaryObject(stackViewComponent, testCase, {initialItem: itemComponent}) verify(control) ignoreWarning("QQmlComponent: Component is not ready") @@ -1010,10 +1248,10 @@ TestCase { } function test_properties() { - var control = createTemporaryObject(stackView, testCase) + let control = createTemporaryObject(stackViewComponent, testCase) verify(control) - var rect = control.push(rectangle, {color: "#ff0000"}) + let rect = control.push(rectangle, {color: "#ff0000"}) compare(rect.color, "#ff0000") compare(rect.initialColor, "#ff0000") } @@ -1030,10 +1268,10 @@ TestCase { } function test_signals() { - var control = createTemporaryObject(stackView, testCase) + let control = createTemporaryObject(stackViewComponent, testCase) verify(control) - var item1 = signalTest.createObject(control) + let item1 = signalTest.createObject(control) compare(item1.StackView.status, StackView.Inactive) control.push(item1) compare(item1.StackView.status, StackView.Active) @@ -1042,7 +1280,7 @@ TestCase { compare(item1.deactivatedSpy.count, 0) compare(item1.deactivatingSpy.count, 0) - var item2 = signalTest.createObject(control) + let item2 = signalTest.createObject(control) compare(item2.StackView.status, StackView.Inactive) control.push(item2) compare(item2.StackView.status, StackView.Activating) @@ -1074,11 +1312,12 @@ TestCase { // QTBUG-56158 function test_repeatedPop() { - var control = createTemporaryObject(stackView, testCase, {initialItem: component, width: testCase.width, height: testCase.height}) + let control = createTemporaryObject(stackViewComponent, testCase, + {initialItem: itemComponent, width: testCase.width, height: testCase.height}) verify(control) - for (var i = 0; i < 12; ++i) - control.push(component) + for (let i = 0; i < 12; ++i) + control.push(itemComponent) tryCompare(control, "busy", false) while (control.depth > 1) { @@ -1089,7 +1328,7 @@ TestCase { } function test_pushSameItem() { - var control = createTemporaryObject(stackView, testCase) + let control = createTemporaryObject(stackViewComponent, testCase) verify(control) control.push(item, StackView.Immediate) @@ -1103,27 +1342,27 @@ TestCase { compare(control.depth, 1) // Push a component so that it becomes current. - var current = control.push(component, StackView.Immediate) + let current = control.push(itemComponent, StackView.Immediate) compare(control.currentItem, current) compare(control.depth, 2) // Push a bunch of stuff. "item" is already in the stack, so it should be ignored. - current = control.push(component, item, StackView.Immediate) + current = control.push(itemComponent, item, StackView.Immediate) verify(current !== item) compare(control.currentItem, current) compare(control.depth, 3) } function test_visible() { - var control = createTemporaryObject(stackView, testCase) + let control = createTemporaryObject(stackViewComponent, testCase) verify(control) - var item1 = component.createObject(control) + let item1 = itemComponent.createObject(control) control.push(item1, StackView.Immediate) compare(item1.visible, true) compare(item1.StackView.visible, item1.visible) - var item2 = component.createObject(control) + let item2 = itemComponent.createObject(control) control.push(item2, StackView.Immediate) compare(item1.visible, false) compare(item2.visible, true) @@ -1132,7 +1371,7 @@ TestCase { // keep explicitly visible item2.StackView.visible = true - control.push(component, StackView.Immediate) + control.push(itemComponent, StackView.Immediate) compare(item2.visible, true) compare(item2.StackView.visible, true) @@ -1166,26 +1405,26 @@ TestCase { } function test_resolveInitialItem() { - var control = createTemporaryObject(stackView, testCase, {initialItem: "TestItem.qml"}) + let control = createTemporaryObject(stackViewComponent, testCase, {initialItem: "TestItem.qml"}) verify(control) verify(control.currentItem) } function test_resolve() { - var control = createTemporaryObject(stackView, testCase) + let control = createTemporaryObject(stackViewComponent, testCase) verify(control) - var item = control.push("TestItem.qml") + let item = control.push("TestItem.qml") compare(control.depth, 1) verify(item) } // QTBUG-65084 function test_mouseArea() { - var ma = createTemporaryObject(mouseArea, testCase, {width: testCase.width, height: testCase.height}) + let ma = createTemporaryObject(mouseArea, testCase, {width: testCase.width, height: testCase.height}) verify(ma) - var control = stackView.createObject(ma, {width: testCase.width, height: testCase.height}) + let control = stackViewComponent.createObject(ma, {width: testCase.width, height: testCase.height}) verify(control) mousePress(control) @@ -1194,7 +1433,7 @@ TestCase { mouseRelease(control) verify(!ma.pressed) - var touch = touchEvent(control) + let touch = touchEvent(control) touch.press(0, control).commit() verify(ma.pressed) @@ -1204,14 +1443,14 @@ TestCase { // Separate function to ensure that the temporary value created to hold the return value of the Qt.createComponent() // call is out of scope when the caller calls gc(). - function stackViewFactory() + function stackViewFactory() : T.StackView { - return createTemporaryObject(stackView, testCase, {initialItem: Qt.createComponent("TestItem.qml")}) + return createTemporaryObject(stackViewComponent, testCase, {initialItem: Qt.createComponent("TestItem.qml")}) } function test_initalItemOwnership() { - var control = stackViewFactory() + let control = stackViewFactory() verify(control) gc() verify(control.initialItem) @@ -1237,7 +1476,7 @@ TestCase { // We don't actually do this on destruction because destruction is delayed. // Rather, we do it when we get un-parented. if (parent === null) - container.onDestructionCallback(stackView) + container.onDestructionCallback(stackView) // qmllint disable use-proper-function } } } @@ -1288,7 +1527,7 @@ TestCase { let control = container.control // Push an extra item so that we can call pop(null) and reproduce the conditions for the crash. - control.push(component, StackView.Immediate) + control.push(itemComponent, StackView.Immediate) control.push(container.clearUponDestructionComponent, StackView.Immediate) // Pop the top item, then pop down to the first item in response. @@ -1306,12 +1545,12 @@ TestCase { // Replace the top item, then clear in response. ignoreWarning(/.*cannot clear while already in the process of completing a replace/) - control.replace(component, StackView.Immediate) + control.replace(itemComponent, StackView.Immediate) } function test_recursiveClearReplace() { let container = createTemporaryObject(clearUponDestructionContainerComponent, testCase, - { onDestructionCallback: function(stackView) { stackView.replace(component, StackView.Immediate) }}) + { onDestructionCallback: function(stackView) { stackView.replace(itemComponent, StackView.Immediate) }}) verify(container) let control = container.control @@ -1383,7 +1622,7 @@ TestCase { // QTBUG-84381 function test_clearAndPushAfterDepthChange() { - var control = createTemporaryObject(stackView, testCase, { + let control = createTemporaryObject(stackViewComponent, testCase, { popEnter: null, popExit: null, pushEnter: null, pushExit: null, replaceEnter: null, replaceExit: null }) @@ -1396,12 +1635,12 @@ TestCase { control.clear() // Shouldn't crash. ignoreWarning(/.*QML StackView: cannot push while already in the process of completing a push/) - control.push(component) + control.push(itemComponent) } }) - control.push(component) - control.push(component) + control.push(itemComponent) + control.push(itemComponent) } // QTBUG-96966 @@ -1516,8 +1755,9 @@ TestCase { } function test_requiredProperties() { - var control = createTemporaryObject(stackView, testCase) + let control = createTemporaryObject(stackViewComponent, testCase) verify(control) + ignoreWarning(/QML StackView: push: Property i was marked as required but not set/) let failedPush = control.push(withRequired) compare(failedPush, null); control.push(withRequired, {"i": 42}) @@ -1564,7 +1804,7 @@ TestCase { StackView { id: stackView anchors.fill: parent - initialItem: cppComponent + initialItem: stackView.cppComponent property Component cppComponent: ComponentCreator.createComponent("import QtQuick; Rectangle { color: \"navajowhite\" }") } @@ -1601,4 +1841,42 @@ TestCase { control.push(noProperties, { "unknownProperty.test": "crashes" }) verify(!control.empty) } + + Component { + id: deletePoppedItem + + StackView { + id: stackView + anchors.fill: parent + property int visibleChangedCounter + property bool secondDestroyed: false + initialItem: Text { + text: "First" + onVisibleChanged: { + ++visibleChangedCounter + if (visible) + tryVerify(function() { return secondDestroyed; }) + } + } + } + } + + Component { + id: otherComp + Text { + text: "Second" + property var stackView + Component.onDestruction: stackView.secondDestroyed = true + } + } + + function test_deletePoppedItem() { + let control = createTemporaryObject(deletePoppedItem, testCase) + verify(control) + control.push(otherComp) + tryCompare(control, "visibleChangedCounter", 1) + control.currentItem.stackView = control + let item = control.pop() + tryCompare(control, "visibleChangedCounter", 2) + } } diff --git a/tests/auto/quickcontrols/controls/data/tst_swipedelegate.qml b/tests/auto/quickcontrols/controls/data/tst_swipedelegate.qml index 901170bf9f..4e4022a1c5 100644 --- a/tests/auto/quickcontrols/controls/data/tst_swipedelegate.qml +++ b/tests/auto/quickcontrols/controls/data/tst_swipedelegate.qml @@ -1,5 +1,5 @@ // Copyright (C) 2017 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only import QtQuick import QtTest @@ -86,12 +86,12 @@ TestCase { } function test_horizontalAnchors(data) { - var warningMessage = Qt.resolvedUrl("tst_swipedelegate.qml") + data.warningLocation + let warningMessage = Qt.resolvedUrl("tst_swipedelegate.qml") + data.warningLocation + ": QML QQuickItem: SwipeDelegate: cannot use horizontal anchors with " + data.itemName + "; unable to layout the item." ignoreWarning(warningMessage); - var control = createTemporaryObject(data.component, testCase); + let control = createTemporaryObject(data.component, testCase); verify(control.contentItem); } @@ -144,7 +144,7 @@ TestCase { // Sanity check. compare(control.swipe.position, from); - var distance = (to - from) * control.width; + let distance = (to - from) * control.width; mousePress(control, control.width / 2, control.height / 2, Qt.LeftButton); mouseMove(control, control.width / 2 + distance, control.height / 2); @@ -166,7 +166,7 @@ TestCase { } function test_settingDelegates() { - var control = createTemporaryObject(swipeDelegateComponent, testCase); + let control = createTemporaryObject(swipeDelegateComponent, testCase); verify(control); ignoreWarning(/QML SwipeDelegate: cannot set both behind and left\/right properties/) @@ -200,8 +200,8 @@ TestCase { // First, try the left item. swipe(control, 0.0, 1.0); - var oldLeft = control.swipe.left; - var oldLeftItem = control.swipe.leftItem; + let oldLeft = control.swipe.left; + let oldLeftItem = control.swipe.leftItem; ignoreWarning(/QML SwipeDelegate: left\/right\/behind properties may only be set when swipe.position is 0/) control.swipe.left = null; compare(control.swipe.left, oldLeft); @@ -210,8 +210,8 @@ TestCase { // Try the same thing with the right item. swipe(control, 1.0, -1.0); - var oldRight = control.swipe.right; - var oldRightItem = control.swipe.rightItem; + let oldRight = control.swipe.right; + let oldRightItem = control.swipe.rightItem; ignoreWarning(/QML SwipeDelegate: left\/right\/behind properties may only be set when swipe.position is 0/) control.swipe.right = null; compare(control.swipe.right, oldRight); @@ -235,18 +235,20 @@ TestCase { swipe(control, 0.0, 1.0); - var oldBehind = control.swipe.behind; - var oldBehindItem = control.swipe.behindItem; + let oldBehind = control.swipe.behind; + let oldBehindItem = control.swipe.behindItem; ignoreWarning(/QML SwipeDelegate: left\/right\/behind properties may only be set when swipe.position is 0/) control.swipe.behind = null; compare(control.swipe.behind, oldBehind); compare(control.swipe.behindItem, oldBehindItem); } - function test_defaults() { + function init() { failOnWarning(/.?/) + } - var control = createTemporaryObject(swipeDelegateComponent, testCase); + function test_defaults() { + let control = createTemporaryObject(swipeDelegateComponent, testCase); verify(control); compare(control.baselineOffset, control.contentItem.y + control.contentItem.baselineOffset); @@ -261,20 +263,20 @@ TestCase { } function test_swipe() { - var control = createTemporaryObject(swipeDelegateComponent, testCase); + let control = createTemporaryObject(swipeDelegateComponent, testCase); verify(control); - var overDragDistance = Math.round(dragDistance * 1.1); + let overDragDistance = Math.round(dragDistance * 1.1); - var completedSpy = signalSpyComponent.createObject(control, { target: control.swipe, signalName: "completed" }); + let completedSpy = signalSpyComponent.createObject(control, { target: control.swipe, signalName: "completed" }); verify(completedSpy); verify(completedSpy.valid); - var openedSpy = signalSpyComponent.createObject(control, { target: control.swipe, signalName: "opened" }); + let openedSpy = signalSpyComponent.createObject(control, { target: control.swipe, signalName: "opened" }); verify(openedSpy); verify(openedSpy.valid); - var closedSpy = signalSpyComponent.createObject(control, { target: control.swipe, signalName: "closed" }); + let closedSpy = signalSpyComponent.createObject(control, { target: control.swipe, signalName: "closed" }); verify(closedSpy); verify(closedSpy.valid); @@ -437,10 +439,10 @@ TestCase { function test_swipeVelocity(data) { skip("QTBUG-52003"); - var control = createTemporaryObject(swipeDelegateComponent, testCase); + let control = createTemporaryObject(swipeDelegateComponent, testCase); verify(control); - var distance = Math.round(dragDistance * 1.1); + let distance = Math.round(dragDistance * 1.1); if (distance >= control.width / 2) skip("This test requires a startDragDistance that is less than half the width of the control"); @@ -464,10 +466,10 @@ TestCase { verify(control.swipe.position < 0.5); verify(!control.swipe.complete); - var expectedVisibleItem; - var expectedVisibleObjectName; - var expectedHiddenItem; - var expectedContentItemX; + let expectedVisibleItem; + let expectedVisibleObjectName; + let expectedHiddenItem; + let expectedContentItemX; if (distance > 0) { expectedVisibleObjectName = "leftItem"; expectedVisibleItem = control.swipe.leftItem; @@ -505,7 +507,9 @@ TestCase { text: "SwipeDelegate" width: 150 swipe.right: Button { - width: parent.width + // make the button a bit shorter than the delegate, so + // that we're able to release the mouse outside of it + width: parent.width - 4 height: parent.height text: "Boo!" } @@ -513,10 +517,10 @@ TestCase { } function test_eventsToLeftAndRight() { - var control = createTemporaryObject(swipeDelegateWithButtonComponent, testCase); + let control = createTemporaryObject(swipeDelegateWithButtonComponent, testCase); verify(control); - var closedSpy = signalSpyComponent.createObject(control, { target: control.swipe, signalName: "closed" }); + let closedSpy = signalSpyComponent.createObject(control, { target: control.swipe, signalName: "closed" }); verify(closedSpy); verify(closedSpy.valid); @@ -529,20 +533,20 @@ TestCase { verify(control.swipe.rightItem.visible); compare(control.swipe.rightItem.parent, control); - var buttonPressedSpy = signalSpyComponent.createObject(control, { target: control.swipe.rightItem, signalName: "pressed" }); + let buttonPressedSpy = signalSpyComponent.createObject(control, { target: control.swipe.rightItem, signalName: "pressed" }); verify(buttonPressedSpy); verify(buttonPressedSpy.valid); - var buttonReleasedSpy = signalSpyComponent.createObject(control, { target: control.swipe.rightItem, signalName: "released" }); + let buttonReleasedSpy = signalSpyComponent.createObject(control, { target: control.swipe.rightItem, signalName: "released" }); verify(buttonReleasedSpy); verify(buttonReleasedSpy.valid); - var buttonClickedSpy = signalSpyComponent.createObject(control, { target: control.swipe.rightItem, signalName: "clicked" }); + let buttonClickedSpy = signalSpyComponent.createObject(control, { target: control.swipe.rightItem, signalName: "clicked" }); verify(buttonClickedSpy); verify(buttonClickedSpy.valid); // Now press the button. mousePress(control, control.width / 2, control.height / 2); verify(!control.pressed); - var button = control.swipe.rightItem; + let button = control.swipe.rightItem; verify(button.pressed); compare(buttonPressedSpy.count, 1); compare(buttonReleasedSpy.count, 0); @@ -564,10 +568,26 @@ TestCase { verify(!button.pressed); mouseRelease(control, control.width / 2, control.height / 2); verify(!control.pressed); + + // Try to press the button again, but drag and release outside of it. + // This should not click the button. + buttonClickedSpy.clear(); + // Open the control, and press the button + mouseDrag(control, control.width / 2, control.height / 2, -control.width, 0); + mousePress(control); + verify(button.pressed); + + // Drag the mouse outside the button, and release + mouseMove(control, control.width - 2, control.height / 2, -1, Qt.LeftButton); + mouseRelease(control); + verify(!button.pressed); + verify(!button.hovered); + // This should not be a click + compare(buttonClickedSpy.count, 0); } function test_mouseButtons() { - var control = createTemporaryObject(swipeDelegateComponent, testCase); + let control = createTemporaryObject(swipeDelegateComponent, testCase); verify(control); // click @@ -609,7 +629,7 @@ TestCase { verify(mouseSignalSequenceSpy.success); // press and hold - var pressAndHoldSpy = signalSpyComponent.createObject(control, { target: control, signalName: "pressAndHold" }); + let pressAndHoldSpy = signalSpyComponent.createObject(control, { target: control, signalName: "pressAndHold" }); verify(pressAndHoldSpy); verify(pressAndHoldSpy.valid); @@ -691,27 +711,45 @@ TestCase { } } + function test_removableDelegates_data() { + return [ + { tag: "mouse", touch: false }, + { tag: "touch", touch: true } + ] + } + function test_removableDelegates() { - var listView = createTemporaryObject(removableDelegatesComponent, testCase); + let listView = createTemporaryObject(removableDelegatesComponent, testCase); verify(listView); compare(listView.count, 3); + let touch = data.touch ? touchEvent(listView) : null + // Expose the remove button. - var firstItem = listView.itemAt(0, 0); - mousePress(listView, firstItem.width / 2, firstItem.height / 2); + let firstItem = listView.itemAt(0, 0); + if (data.touch) + touch.press(0, listView, firstItem.width / 2, firstItem.height / 2).commit() + else + mousePress(listView, firstItem.width / 2, firstItem.height / 2); verify(firstItem.pressed); compare(firstItem.swipe.position, 0.0); verify(!firstItem.swipe.complete); verify(!firstItem.swipe.leftItem); - mouseMove(listView, firstItem.width * 1.1, firstItem.height / 2); + if (data.touch) + touch.move(0, listView, firstItem.width * 1.1, firstItem.height / 2).commit() + else + mouseMove(listView, firstItem.width * 1.1, firstItem.height / 2); verify(firstItem.pressed); compare(firstItem.swipe.position, 0.6); verify(!firstItem.swipe.complete); verify(firstItem.swipe.leftItem); verify(!firstItem.swipe.leftItem.SwipeDelegate.pressed); - mouseRelease(listView, firstItem.width / 2, firstItem.height / 2); + if (data.touch) + touch.release(0, listView, firstItem.width / 2, firstItem.height / 2).commit() + else + mouseRelease(listView, firstItem.width / 2, firstItem.height / 2); verify(!firstItem.pressed); tryCompare(firstItem.swipe, "position", 1.0); tryCompare(firstItem.swipe, "complete", true); @@ -720,19 +758,32 @@ TestCase { // Wait for it to settle down. tryCompare(firstItem.contentItem, "x", firstItem.leftPadding + firstItem.width); - var leftClickedSpy = signalSpyComponent.createObject(firstItem.swipe.leftItem, + let leftClickedSpy = signalSpyComponent.createObject(firstItem.swipe.leftItem, { target: firstItem.swipe.leftItem.SwipeDelegate, signalName: "clicked" }); verify(leftClickedSpy); verify(leftClickedSpy.valid); // Click the left item to remove the delegate from the list. - var contentItemX = firstItem.contentItem.x; - mousePress(listView, firstItem.width / 2, firstItem.height / 2); + let contentItemX = firstItem.contentItem.x; + // press + if (data.touch) + touch.press(0, listView, firstItem.width / 2, firstItem.height / 2).commit() + else + mousePress(listView, firstItem.width / 2, firstItem.height / 2); verify(firstItem.swipe.leftItem.SwipeDelegate.pressed); compare(leftClickedSpy.count, 0); verify(firstItem.pressed); - mouseRelease(listView, firstItem.width / 2, firstItem.height / 2); + // simulate inadvertent movement which can easily happen + if (data.touch) + touch.move(0, listView, firstItem.width / 2 + 1, firstItem.height / 2).commit() + else + mouseMove(listView, firstItem.width / 2 + 1, firstItem.height / 2); + // release + if (data.touch) + touch.release(0, listView, firstItem.width / 2, firstItem.height / 2).commit() + else + mouseRelease(listView, firstItem.width / 2, firstItem.height / 2); verify(!firstItem.swipe.leftItem.SwipeDelegate.pressed); compare(leftClickedSpy.count, 1); verify(!firstItem.pressed); @@ -806,7 +857,7 @@ TestCase { } function test_leadingTrailing(data) { - var control = createTemporaryObject(data.component, testCase); + let control = createTemporaryObject(data.component, testCase); verify(control); mousePress(control, control.width / 2, control.height / 2, Qt.LeftButton); @@ -817,7 +868,7 @@ TestCase { } function test_minMaxPosition() { - var control = createTemporaryObject(leadingTrailingXComponent, testCase); + let control = createTemporaryObject(leadingTrailingXComponent, testCase); verify(control); // Should be limited within the range -1.0 to 1.0. @@ -853,13 +904,13 @@ TestCase { // swipe.position should be scaled to the width of the relevant delegate, // and it shouldn't be possible to drag past the delegate (so that content behind the control is visible). function test_delegateWidth() { - var control = createTemporaryObject(emptySwipeDelegateComponent, testCase); + let control = createTemporaryObject(emptySwipeDelegateComponent, testCase); verify(control); control.swipe.left = smallLeftComponent; // Ensure that the position is scaled to the width of the currently visible delegate. - var overDragDistance = Math.round(dragDistance * 1.1); + let overDragDistance = Math.round(dragDistance * 1.1); mousePress(control, control.width / 2, control.height / 2, Qt.LeftButton); mouseMove(control, control.width / 2 + overDragDistance, control.height / 2); verify(control.swipe.leftItem); @@ -891,7 +942,7 @@ TestCase { } function test_positionAfterSwipeCompleted() { - var control = createTemporaryObject(swipeDelegateComponent, testCase); + let control = createTemporaryObject(swipeDelegateComponent, testCase); verify(control); // Ensure that both delegates are constructed. @@ -916,7 +967,7 @@ TestCase { mousePress(control, control.swipe.leftItem.width - 1, control.height / 2, Qt.LeftButton); compare(leftVisibleSpy.count, 0); compare(rightVisibleSpy.count, 0); - var newX = control.swipe.leftItem.width - Math.round(dragDistance * 1.1) -1; + let newX = control.swipe.leftItem.width - Math.round(dragDistance * 1.1) -1; mouseMove(control, newX, control.height / 2); compare(leftVisibleSpy.count, 0); compare(rightVisibleSpy.count, 0); @@ -986,7 +1037,7 @@ TestCase { } function test_leadingTrailingBehindItem() { - var control = createTemporaryObject(behindSwipeDelegateComponent, testCase); + let control = createTemporaryObject(behindSwipeDelegateComponent, testCase); verify(control); swipe(control, 0.0, 1.0); @@ -1038,10 +1089,10 @@ TestCase { } function test_close() { - var control = createTemporaryObject(closeSwipeDelegateComponent, testCase); + let control = createTemporaryObject(closeSwipeDelegateComponent, testCase); verify(control); - var closedSpy = signalSpyComponent.createObject(control, { target: control.swipe, signalName: "closed" }); + let closedSpy = signalSpyComponent.createObject(control, { target: control.swipe, signalName: "closed" }); verify(closedSpy); verify(closedSpy.valid); @@ -1173,14 +1224,14 @@ TestCase { // Tests that it's possible to have multiple non-interactive items in one delegate // (e.g. left/right/behind) that can each receive clicks. function test_multipleClickableActions() { - var control = createTemporaryObject(multiActionSwipeDelegateComponent, testCase); + let control = createTemporaryObject(multiActionSwipeDelegateComponent, testCase); verify(control); swipe(control, 0.0, -1.0); verify(control.swipe.rightItem); tryCompare(control.swipe, "complete", true); - var firstClickedSpy = signalSpyComponent.createObject(control, + let firstClickedSpy = signalSpyComponent.createObject(control, { target: control.swipe.rightItem.firstAction.SwipeDelegate, signalName: "clicked" }); verify(firstClickedSpy); verify(firstClickedSpy.valid); @@ -1204,7 +1255,7 @@ TestCase { compare(firstClickedSpy.count, 1); compare(control.swipe.rightItem.firstClickCount, 1); - var secondClickedSpy = signalSpyComponent.createObject(control, + let secondClickedSpy = signalSpyComponent.createObject(control, { target: control.swipe.rightItem.secondAction.SwipeDelegate, signalName: "clicked" }); verify(secondClickedSpy); verify(secondClickedSpy.valid); @@ -1280,25 +1331,25 @@ TestCase { // rotation, for example), the positions of the contentItem and background items // should be updated accordingly. function test_contentItemPosOnWidthChanged() { - var control = createTemporaryObject(swipeDelegateComponent, testCase); + let control = createTemporaryObject(swipeDelegateComponent, testCase); verify(control); swipe(control, 0.0, 1.0); - var oldContentItemX = control.contentItem.x; - var oldBackgroundX = control.background.x; + let oldContentItemX = control.contentItem.x; + let oldBackgroundX = control.background.x; control.width += 100; compare(control.contentItem.x, oldContentItemX + 100); compare(control.background.x, oldBackgroundX + 100); } function test_contentItemHeightOnHeightChanged() { - var control = createTemporaryObject(swipeDelegateComponent, testCase); + let control = createTemporaryObject(swipeDelegateComponent, testCase); verify(control); // Try when swipe.complete is false. - var originalHeight = control.height; - var originalContentItemHeight = control.contentItem.height; + let originalHeight = control.height; + let originalContentItemHeight = control.contentItem.height; verify(control.height !== 10); control.height = 10; compare(control.contentItem.height, control.availableHeight); @@ -1322,7 +1373,7 @@ TestCase { } function test_releaseOutside(data) { - var control = createTemporaryObject(data.component, testCase); + let control = createTemporaryObject(data.component, testCase); verify(control); // Press and then release below the control. @@ -1337,7 +1388,7 @@ TestCase { verify(mouseSignalSequenceSpy.success); // Press and then release to the right of the control. - var hasDelegates = control.swipe.left || control.swipe.right || control.swipe.behind; + let hasDelegates = control.swipe.left || control.swipe.right || control.swipe.behind; mouseSignalSequenceSpy.target = control; mouseSignalSequenceSpy.expectedSequence = hasDelegates ? [["pressedChanged", { "pressed": true }], "pressed"] @@ -1405,7 +1456,7 @@ TestCase { } function test_beginSwipeOverRightItem() { - var control = createTemporaryObject(leftRightWithLabelsComponent, testCase); + let control = createTemporaryObject(leftRightWithLabelsComponent, testCase); verify(control); // Swipe to the left, exposing the right item. @@ -1416,8 +1467,8 @@ TestCase { // TODO: Swipe to the left, with the mouse over the Label in the right item. // The left item should not become visible at any point. - var rightLabel = control.swipe.rightItem.label; - var overDragDistance = Math.round(dragDistance * 1.1); + let rightLabel = control.swipe.rightItem.label; + let overDragDistance = Math.round(dragDistance * 1.1); mousePress(rightLabel, rightLabel.width / 2, rightLabel.height / 2, Qt.rightButton); mouseMove(rightLabel, rightLabel.width / 2 - overDragDistance, rightLabel.height / 2); verify(!control.swipe.leftItem); @@ -1450,7 +1501,7 @@ TestCase { } function test_swipeEnabled() { - var control = createTemporaryObject(swipeDelegateDisabledComponent, testCase); + let control = createTemporaryObject(swipeDelegateDisabledComponent, testCase); mousePress(control, control.width / 2, control.height / 2); verify(control.pressed); @@ -1460,7 +1511,7 @@ TestCase { verify(!control.swipe.rightItem); // It shouldn't be possible to swipe. - var overDragDistance = Math.round(dragDistance * 1.1); + let overDragDistance = Math.round(dragDistance * 1.1); mouseMove(control, control.width / 2 - overDragDistance, control.height / 2); verify(control.pressed); compare(control.swipe.position, 0.0); @@ -1527,7 +1578,7 @@ TestCase { } function test_open_side(data) { - var control = createTemporaryObject(emptySwipeDelegateComponent, testCase, + let control = createTemporaryObject(emptySwipeDelegateComponent, testCase, {"swipe.left": data.left, "swipe.right": data.right, "swipe.behind": data.behind}); verify(control); @@ -1553,7 +1604,7 @@ TestCase { } function test_open() { - var control = createTemporaryObject(openSwipeDelegateComponent, testCase); + let control = createTemporaryObject(openSwipeDelegateComponent, testCase); verify(control); mouseClick(control); @@ -1599,7 +1650,7 @@ TestCase { function test_animations() { // Test that animations are run when releasing from a drag. - var control = createTemporaryObject(animationSwipeDelegateComponent, testCase); + let control = createTemporaryObject(animationSwipeDelegateComponent, testCase); verify(control); mousePress(control, control.width / 2, control.height / 2, Qt.LeftButton); @@ -1615,11 +1666,11 @@ TestCase { } function test_spacing() { - var control = createTemporaryObject(swipeDelegateComponent, testCase, { text: "Some long, long, long text" }) + let control = createTemporaryObject(swipeDelegateComponent, testCase, { text: "Some long, long, long text" }) verify(control) verify(control.contentItem.implicitWidth + control.leftPadding + control.rightPadding > control.background.implicitWidth) - var textLabel = findChild(control.contentItem, "label") + let textLabel = findChild(control.contentItem, "label") verify(textLabel) // The implicitWidth of the IconLabel that all buttons use as their contentItem @@ -1648,7 +1699,7 @@ TestCase { } function test_display(data) { - var control = createTemporaryObject(swipeDelegateComponent, testCase, { + let control = createTemporaryObject(swipeDelegateComponent, testCase, { text: "SwipeDelegate", display: data.display, width: 400, @@ -1658,8 +1709,8 @@ TestCase { verify(control) compare(control.icon.source, "qrc:/qt-project.org/imports/QtQuick/Controls/Basic/images/check.png") - var iconImage = findChild(control.contentItem, "image") - var textLabel = findChild(control.contentItem, "label") + let iconImage = findChild(control.contentItem, "image") + let textLabel = findChild(control.contentItem, "label") switch (control.display) { case SwipeDelegate.IconOnly: @@ -1747,4 +1798,47 @@ TestCase { swipe(control, 0, -1.0) compare(control.swipe.rightItem.color, Qt.color("tomato")) } + + + Component { + id: swipeDelegate + + SwipeDelegate { + anchors.centerIn: parent + width: 100 + height: 50 + contentItem: Rectangle { + color: "red" + } + swipe.right: Row { + height: parent.height + anchors.right: parent.right + property alias buttonItem: button + Button { + id: button + width: 50 + height: parent.height + text: "Button" + } + } + } + } + + function test_mouseEventOnNonVisualItem() { + let control = createTemporaryObject(swipeDelegate, testCase) + verify(control) + + swipe(control, 0, -1.0) + verify(control.swipe.rightItem.visible) + + let rightItem = control.swipe.rightItem + let rightClickSpy = signalSpyComponent.createObject(control, + { target: rightItem.buttonItem, signalName: "clicked" }) + verify(rightClickSpy) + verify(rightClickSpy.valid) + + mouseClick(rightItem) + + compare(rightClickSpy.count, 1) + } } diff --git a/tests/auto/quickcontrols/controls/data/tst_swipeview.qml b/tests/auto/quickcontrols/controls/data/tst_swipeview.qml index c853f6dd55..8d59c4a09a 100644 --- a/tests/auto/quickcontrols/controls/data/tst_swipeview.qml +++ b/tests/auto/quickcontrols/controls/data/tst_swipeview.qml @@ -1,5 +1,5 @@ // Copyright (C) 2017 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only import QtQuick import QtTest @@ -28,24 +28,26 @@ TestCase { SignalSpy { } } - function test_defaults() { + function init() { failOnWarning(/.?/) + } + function test_defaults() { let control = createTemporaryObject(swipeView, testCase) verify(control) } function test_current() { - var control = createTemporaryObject(swipeView, testCase) + let control = createTemporaryObject(swipeView, testCase) - var currentItemChangedSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "currentItemChanged"}) + let currentItemChangedSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "currentItemChanged"}) verify(currentItemChangedSpy.valid) compare(control.count, 0) compare(control.currentIndex, -1) compare(control.currentItem, null) - var item0 = page.createObject(control, {text: "0"}) + let item0 = page.createObject(control, {text: "0"}) control.addItem(item0) compare(control.count, 1) compare(control.currentIndex, 0) @@ -54,7 +56,7 @@ TestCase { compare(control.contentWidth, item0.implicitWidth) compare(control.contentHeight, item0.implicitHeight) - var item1 = page.createObject(control, {text: "11"}) + let item1 = page.createObject(control, {text: "11"}) control.addItem(item1) compare(control.count, 2) compare(control.currentIndex, 0) @@ -63,7 +65,7 @@ TestCase { compare(control.contentWidth, item0.implicitWidth) compare(control.contentHeight, item0.implicitHeight) - var item2 = page.createObject(control, {text: "222"}) + let item2 = page.createObject(control, {text: "222"}) control.addItem(item2) compare(control.count, 3) compare(control.currentIndex, 0) @@ -119,7 +121,7 @@ TestCase { } function test_initialCurrent() { - var control = createTemporaryObject(initialCurrentSwipeView, testCase) + let control = createTemporaryObject(initialCurrentSwipeView, testCase) compare(control.count, 2) compare(control.currentIndex, 1) @@ -127,7 +129,7 @@ TestCase { } function test_addRemove() { - var control = createTemporaryObject(swipeView, testCase) + let control = createTemporaryObject(swipeView, testCase) function verifyCurrentIndexCountDiff() { verify(control.currentIndex < control.count) @@ -135,7 +137,7 @@ TestCase { control.currentIndexChanged.connect(verifyCurrentIndexCountDiff) control.countChanged.connect(verifyCurrentIndexCountDiff) - var currentItemChangedSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "currentItemChanged"}) + let currentItemChangedSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "currentItemChanged"}) verify(currentItemChangedSpy.valid) compare(control.count, 0) @@ -235,12 +237,12 @@ TestCase { } function test_content() { - var control = createTemporaryObject(contentView, testCase) + let control = createTemporaryObject(contentView, testCase) function compareObjectNames(content, names) { if (content.length !== names.length) return false - for (var i = 0; i < names.length; ++i) { + for (let i = 0; i < names.length; ++i) { if (content[i].objectName !== names[i]) return false } @@ -280,20 +282,20 @@ TestCase { } function test_repeater() { - var control = createTemporaryObject(repeated, testCase) + let control = createTemporaryObject(repeated, testCase) verify(control) - var model = control.contentModel + let model = control.contentModel verify(model) - var repeater = control.repeater + let repeater = control.repeater verify(repeater) compare(repeater.count, 5) compare(model.count, 5) - for (var i = 0; i < 5; ++i) { - var item1 = control.itemAt(i) + for (let i = 0; i < 5; ++i) { + let item1 = control.itemAt(i) verify(item1) compare(item1.idx, i) compare(model.get(i), item1) @@ -304,8 +306,8 @@ TestCase { compare(repeater.count, 3) compare(model.count, 3) - for (var j = 0; j < 3; ++j) { - var item2 = control.itemAt(j) + for (let j = 0; j < 3; ++j) { + let item2 = control.itemAt(j) verify(item2) compare(item2.idx, j) compare(model.get(j), item2) @@ -334,7 +336,7 @@ TestCase { } function test_order() { - var control = createTemporaryObject(ordered, testCase) + let control = createTemporaryObject(ordered, testCase) verify(control) compare(control.count, 7) @@ -395,14 +397,14 @@ TestCase { } function test_move(data) { - var control = createTemporaryObject(swipeView, testCase) + let control = createTemporaryObject(swipeView, testCase) compare(control.count, 0) - var titles = ["1", "2", "3"] + let titles = ["1", "2", "3"] - var i = 0; + let i = 0; for (i = 0; i < titles.length; ++i) { - var item = pageAttached.createObject(control, {text: titles[i]}) + let item = pageAttached.createObject(control, {text: titles[i]}) control.addItem(item) } @@ -427,7 +429,7 @@ TestCase { compare(control.count, titles.length) compare(control.currentIndex, data.currentAfter) - var title = titles[data.from] + let title = titles[data.from] titles.splice(data.from, 1) titles.splice(data.to, 0, title) @@ -455,13 +457,13 @@ TestCase { } function test_dynamic() { - var control = createTemporaryObject(dynamicView, testCase) + let control = createTemporaryObject(dynamicView, testCase) // insertItem(), addItem(), createObject() and static page {} compare(control.count, 4) compare(control.itemAt(0).text, "inserted") - var tab = page.createObject(control, {text: "dying"}) + let tab = page.createObject(control, {text: "dying"}) compare(control.count, 5) compare(control.itemAt(4).text, "dying") @@ -472,9 +474,9 @@ TestCase { } function test_attachedParent() { - var control = createTemporaryObject(swipeView, testCase); + let control = createTemporaryObject(swipeView, testCase); - var page = createTemporaryObject(pageAttached, testCase); + let page = createTemporaryObject(pageAttached, testCase); compare(page.view, null); compare(page.index, -1); compare(page.isCurrentItem, false); @@ -509,17 +511,17 @@ TestCase { } function test_orientation() { - var control = createTemporaryObject(swipeView, testCase, {width: 200, height: 200}) + let control = createTemporaryObject(swipeView, testCase, {width: 200, height: 200}) verify(control) - for (var i = 0; i < 3; ++i) + for (let i = 0; i < 3; ++i) control.addItem(page.createObject(control, {text: i})) compare(control.orientation, Qt.Horizontal) compare(control.horizontal, true) compare(control.vertical, false) - for (i = 0; i < control.count; ++i) { + for (let i = 0; i < control.count; ++i) { control.currentIndex = i compare(control.itemAt(i).y, 0) } @@ -529,7 +531,7 @@ TestCase { compare(control.horizontal, false) compare(control.vertical, true) - for (i = 0; i < control.count; ++i) { + for (let i = 0; i < control.count; ++i) { control.currentIndex = i compare(control.itemAt(i).x, 0) } @@ -564,7 +566,7 @@ TestCase { if (Qt.styleHints.tabFocusBehavior !== Qt.TabFocusAllControls) skip("This platform only allows tab focus for text controls") - var control = createTemporaryObject(focusSwipeViewComponent, testCase) + let control = createTemporaryObject(focusSwipeViewComponent, testCase) verify(control) compare(control.focus, true) compare(control.contentItem.focus, true) @@ -643,7 +645,7 @@ TestCase { tryCompare(rect, "visible", true) if (Qt.platform.pluginName === "offscreen") skip("grabImage() is not functional on the offscreen platform (QTBUG-63185)") - var image = grabImage(control) + let image = grabImage(control) compare(image.pixel(3, 3), "#ffff00") } @@ -651,7 +653,10 @@ TestCase { id: translucentPages SwipeView { spacing: 10 - padding: 10 + leftPadding: 10 + topPadding: 10 + rightPadding: 10 + bottomPadding: 10 Text { text: "page 0" } Text { text: "page 1"; font.pointSize: 16 } Text { text: "page 2"; font.pointSize: 24 } @@ -662,18 +667,97 @@ TestCase { function test_initialPositions() { // QTBUG-102487 const control = createTemporaryObject(translucentPages, testCase, {width: 320, height: 200}) verify(control) + compare(control.contentItem.width, control.width - control.leftPadding - control.rightPadding) + compare(control.spacing, 10) + compare(control.orientation, Qt.Horizontal) - for (var i = 0; i < control.count; ++i) { + for (let i = 0; i < control.count; ++i) { const page = control.itemAt(i) - // control.contentItem.width + control.spacing == 310; except Imagine style has contentItem.width == 320 - compare(page.x, i * 310) + compare(page.x, i * (control.contentItem.width + control.spacing)) compare(page.y, 0) + compare(page.width, control.contentItem.width) + compare(page.height, control.contentItem.height) } control.orientation = Qt.Vertical - for (var i = 0; i < control.count; ++i) { + for (let i = 0; i < control.count; ++i) { const page = control.itemAt(i) compare(page.y, i * (control.contentItem.height + control.spacing)) compare(page.x, 0) + compare(page.width, control.contentItem.width) + compare(page.height, control.contentItem.height) + } + + // QTBUG-115468: add a page after startup and check that that works too. + control.orientation = Qt.Horizontal + let page4 = page.createObject(control, { text: "page 4", "font.pointSize": 40 }) + control.insertItem(control.count, page4) + compare(page4.x, (control.count - 1) * 310) + compare(page4.y, 0) + compare(page4.width, control.contentItem.width) + compare(page4.height, control.contentItem.height) + } + + Component { + id: doublePageWithLabels + SwipeView { + anchors.fill: parent + property alias item1: item1 + property alias item2: item2 + Item { + id: item1 + property alias label: label1 + Label { id: label1; anchors.centerIn: parent; text: "1"; } + } + Item { + id: item2 + property alias label: label2 + Label { id: label2; anchors.centerIn: parent; text: "2"; } + } + } + } + + function test_rightClick_data() { + return [ + { tag: "mouse_left", mouse: true, button: Qt.LeftButton }, + { tag: "mouse_right", mouse: true, button: Qt.RightButton }, + { tag: "touch", touch: true } + ] + } + + function test_rightClick(data) { + let swipeView = createTemporaryObject(doublePageWithLabels, testCase) + verify(swipeView) + let item1 = swipeView.item1 + verify(item1) + let item2 = swipeView.item2 + verify(item2) + let label1 = item1.label + verify(label1) + let label2 = item2.label + verify(label2) + const swipeListView = swipeView.contentItem + verify(swipeListView) + + swipeView.currentIndex = 0 + compare(swipeView.currentIndex, 0) + compare(swipeView.currentItem, item1) + tryCompare(swipeListView, "contentX", 0, 1000) + compare(item2.x, swipeListView.width) + + let touch = data.touch ? touchEvent(swipeView) : null + + if (data.touch) { + touch.press(0, label1, label1.width / 2, label1.height / 2) + touch.commit() + touch.release(0, label1, label1.width / 2, label1.height / 2) + touch.commit() + } else if (data.mouse) { + mouseClick(label1, label1.width / 2, label1.height / 2, data.button) } + swipeView.currentIndex = 1 + compare(swipeView.currentIndex, 1) + compare(swipeView.currentItem, item2) + tryCompare(swipeListView, "contentX", swipeListView.width, 1000) + compare(item2.x, swipeListView.width) } } diff --git a/tests/auto/quickcontrols/controls/data/tst_switch.qml b/tests/auto/quickcontrols/controls/data/tst_switch.qml index 407513b914..40fdbaff0d 100644 --- a/tests/auto/quickcontrols/controls/data/tst_switch.qml +++ b/tests/auto/quickcontrols/controls/data/tst_switch.qml @@ -1,5 +1,5 @@ // Copyright (C) 2017 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only import QtQuick import QtTest @@ -25,15 +25,17 @@ TestCase { } } - function test_defaults() { + function init() { failOnWarning(/.?/) + } + function test_defaults() { let control = createTemporaryObject(swtch, testCase) verify(control) } function test_text() { - var control = createTemporaryObject(swtch, testCase) + let control = createTemporaryObject(swtch, testCase) verify(control) compare(control.text, "") @@ -44,12 +46,12 @@ TestCase { } function test_checked() { - var control = createTemporaryObject(swtch, testCase) + let control = createTemporaryObject(swtch, testCase) verify(control) compare(control.checked, false) - var spy = signalSequenceSpy.createObject(control, {target: control}) + let spy = signalSequenceSpy.createObject(control, {target: control}) spy.expectedSequence = [["checkedChanged", { "checked": true }]] control.checked = true compare(control.checked, true) @@ -69,7 +71,7 @@ TestCase { } function test_pressed(data) { - var control = createTemporaryObject(swtch, testCase, {padding: 10}) + let control = createTemporaryObject(swtch, testCase, {padding: 10}) verify(control) // stays pressed when dragged outside @@ -83,11 +85,11 @@ TestCase { } function test_mouse() { - var control = createTemporaryObject(swtch, testCase) + let control = createTemporaryObject(swtch, testCase) verify(control) // check - var spy = signalSequenceSpy.createObject(control, {target: control}) + let spy = signalSequenceSpy.createObject(control, {target: control}) spy.expectedSequence = [["pressedChanged", { "pressed": true, "checked": false }], "pressed"] mousePress(control, control.width / 2, control.height / 2, Qt.LeftButton) @@ -184,13 +186,13 @@ TestCase { } function test_touch() { - var control = createTemporaryObject(swtch, testCase) + let control = createTemporaryObject(swtch, testCase) verify(control) - var touch = touchEvent(control) + let touch = touchEvent(control) // check - var spy = signalSequenceSpy.createObject(control, {target: control}) + let spy = signalSequenceSpy.createObject(control, {target: control}) spy.expectedSequence = [["pressedChanged", { "pressed": true, "checked": false }], "pressed"] touch.press(0, control, control.width / 2, control.height / 2).commit() @@ -282,10 +284,10 @@ TestCase { } function test_mouseDrag() { - var control = createTemporaryObject(swtch, testCase, {leftPadding: 100, rightPadding: 100}) + let control = createTemporaryObject(swtch, testCase, {leftPadding: 100, rightPadding: 100}) verify(control) - var spy = signalSequenceSpy.createObject(control, {target: control}) + let spy = signalSequenceSpy.createObject(control, {target: control}) compare(control.position, 0.0) compare(control.checked, false) compare(control.pressed, false) @@ -387,12 +389,12 @@ TestCase { } function test_touchDrag() { - var control = createTemporaryObject(swtch, testCase, {leftPadding: 100, rightPadding: 100}) + let control = createTemporaryObject(swtch, testCase, {leftPadding: 100, rightPadding: 100}) verify(control) - var touch = touchEvent(control) + let touch = touchEvent(control) - var spy = signalSequenceSpy.createObject(control, {target: control}) + let spy = signalSequenceSpy.createObject(control, {target: control}) compare(control.position, 0.0) compare(control.checked, false) compare(control.pressed, false) @@ -497,14 +499,14 @@ TestCase { } function test_keys() { - var control = createTemporaryObject(swtch, testCase) + let control = createTemporaryObject(swtch, testCase) verify(control) control.forceActiveFocus() verify(control.activeFocus) // check - var spy = signalSequenceSpy.createObject(control, {target: control}) + let spy = signalSequenceSpy.createObject(control, {target: control}) spy.expectedSequence = [["pressedChanged", { "pressed": true, "checked": false }], "pressed", ["pressedChanged", { "pressed": false, "checked": false }], @@ -532,8 +534,8 @@ TestCase { spy.expectedSequence = [] // Not testing Key_Enter and Key_Return because QGnomeTheme uses them for // pressing buttons and the CI uses the QGnomeTheme platform theme. - var keys = [Qt.Key_Escape, Qt.Key_Tab] - for (var i = 0; i < keys.length; ++i) { + let keys = [Qt.Key_Escape, Qt.Key_Tab] + for (let i = 0; i < keys.length; ++i) { keyClick(keys[i]) compare(control.checked, false) verify(spy.success) @@ -549,7 +551,7 @@ TestCase { } function test_binding() { - var container = createTemporaryObject(twoSwitches, testCase) + let container = createTemporaryObject(twoSwitches, testCase) verify(container) compare(container.sw1.checked, false) @@ -565,13 +567,13 @@ TestCase { } function test_baseline() { - var control = createTemporaryObject(swtch, testCase) + let control = createTemporaryObject(swtch, testCase) verify(control) compare(control.baselineOffset, control.contentItem.y + control.contentItem.baselineOffset) } function test_focus() { - var control = createTemporaryObject(swtch, testCase) + let control = createTemporaryObject(swtch, testCase) verify(control) verify(!control.activeFocus) @@ -597,9 +599,9 @@ TestCase { } function test_deletionOrder() { - var control1 = createTemporaryObject(deletionOrder1, testCase) + let control1 = createTemporaryObject(deletionOrder1, testCase) verify(control1) - var control2 = createTemporaryObject(deletionOrder2, testCase) + let control2 = createTemporaryObject(deletionOrder2, testCase) verify(control2) } } diff --git a/tests/auto/quickcontrols/controls/data/tst_switchdelegate.qml b/tests/auto/quickcontrols/controls/data/tst_switchdelegate.qml index 42d58b9668..c03555f59c 100644 --- a/tests/auto/quickcontrols/controls/data/tst_switchdelegate.qml +++ b/tests/auto/quickcontrols/controls/data/tst_switchdelegate.qml @@ -1,5 +1,5 @@ // Copyright (C) 2017 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only import QtQuick import QtTest @@ -27,27 +27,29 @@ TestCase { // TODO: data-fy tst_checkbox (rename to tst_check?) so we don't duplicate its tests here? - function test_defaults() { + function init() { failOnWarning(/.?/) + } - var control = createTemporaryObject(switchDelegate, testCase); - verify(control); - verify(!control.checked); + function test_defaults() { + let control = createTemporaryObject(switchDelegate, testCase); + verify(control) + verify(!control.checked) } function test_checked() { - var control = createTemporaryObject(switchDelegate, testCase); - verify(control); + let control = createTemporaryObject(switchDelegate, testCase); + verify(control) - mouseClick(control); - verify(control.checked); + mouseClick(control) + verify(control.checked) - mouseClick(control); - verify(!control.checked); + mouseClick(control) + verify(!control.checked) } function test_baseline() { - var control = createTemporaryObject(switchDelegate, testCase); + let control = createTemporaryObject(switchDelegate, testCase); verify(control); compare(control.baselineOffset, control.contentItem.y + control.contentItem.baselineOffset); } @@ -60,7 +62,7 @@ TestCase { } function test_pressed(data) { - var control = createTemporaryObject(switchDelegate, testCase, {padding: 10}) + let control = createTemporaryObject(switchDelegate, testCase, {padding: 10}) verify(control) // stays pressed when dragged outside @@ -74,11 +76,11 @@ TestCase { } function test_mouse() { - var control = createTemporaryObject(switchDelegate, testCase) + let control = createTemporaryObject(switchDelegate, testCase) verify(control) // check - var spy = signalSequenceSpy.createObject(control, {target: control}) + let spy = signalSequenceSpy.createObject(control, {target: control}) spy.expectedSequence = [["pressedChanged", { "pressed": true, "checked": false }], "pressed"] mousePress(control, control.width / 2, control.height / 2, Qt.LeftButton) @@ -175,13 +177,13 @@ TestCase { } function test_touch() { - var control = createTemporaryObject(switchDelegate, testCase) + let control = createTemporaryObject(switchDelegate, testCase) verify(control) - var touch = touchEvent(control) + let touch = touchEvent(control) // check - var spy = signalSequenceSpy.createObject(control, {target: control}) + let spy = signalSequenceSpy.createObject(control, {target: control}) spy.expectedSequence = [["pressedChanged", { "pressed": true, "checked": false }], "pressed"] touch.press(0, control, control.width / 2, control.height / 2).commit() @@ -273,10 +275,10 @@ TestCase { } function test_mouseDrag() { - var control = createTemporaryObject(switchDelegate, testCase, {leftPadding: 100, rightPadding: 100}) + let control = createTemporaryObject(switchDelegate, testCase, {leftPadding: 100, rightPadding: 100}) verify(control) - var spy = signalSequenceSpy.createObject(control, {target: control}) + let spy = signalSequenceSpy.createObject(control, {target: control}) compare(control.position, 0.0) compare(control.checked, false) compare(control.pressed, false) @@ -378,12 +380,12 @@ TestCase { } function test_touchDrag() { - var control = createTemporaryObject(switchDelegate, testCase, {leftPadding: 100, rightPadding: 100}) + let control = createTemporaryObject(switchDelegate, testCase, {leftPadding: 100, rightPadding: 100}) verify(control) - var touch = touchEvent(control) + let touch = touchEvent(control) - var spy = signalSequenceSpy.createObject(control, {target: control}) + let spy = signalSequenceSpy.createObject(control, {target: control}) compare(control.position, 0.0) compare(control.checked, false) compare(control.pressed, false) @@ -488,11 +490,11 @@ TestCase { } function test_spacing() { - var control = createTemporaryObject(switchDelegate, testCase, { text: "Some long, long, long text" }) + let control = createTemporaryObject(switchDelegate, testCase, { text: "Some long, long, long text" }) verify(control) verify(control.contentItem.implicitWidth + control.leftPadding + control.rightPadding > control.background.implicitWidth) - var textLabel = findChild(control.contentItem, "label") + let textLabel = findChild(control.contentItem, "label") verify(textLabel) // The implicitWidth of the IconLabel that all buttons use as their contentItem should be @@ -519,7 +521,7 @@ TestCase { } function test_display(data) { - var control = createTemporaryObject(switchDelegate, testCase, { + let control = createTemporaryObject(switchDelegate, testCase, { text: "SwitchDelegate", display: data.display, width: 400, @@ -529,11 +531,11 @@ TestCase { verify(control) compare(control.icon.source, "qrc:/qt-project.org/imports/QtQuick/Controls/Basic/images/check.png") - var iconImage = findChild(control.contentItem, "image") - var textLabel = findChild(control.contentItem, "label") + let iconImage = findChild(control.contentItem, "image") + let textLabel = findChild(control.contentItem, "label") - var availableWidth = control.availableWidth - control.indicator.width - control.spacing - var indicatorOffset = control.mirrored ? control.indicator.width + control.spacing : 0 + let availableWidth = control.availableWidth - control.indicator.width - control.spacing + let indicatorOffset = control.mirrored ? control.indicator.width + control.spacing : 0 switch (control.display) { case SwitchDelegate.IconOnly: diff --git a/tests/auto/quickcontrols/controls/data/tst_tabbar.qml b/tests/auto/quickcontrols/controls/data/tst_tabbar.qml index 58c0b1ae61..19ba2a9678 100644 --- a/tests/auto/quickcontrols/controls/data/tst_tabbar.qml +++ b/tests/auto/quickcontrols/controls/data/tst_tabbar.qml @@ -1,5 +1,5 @@ // Copyright (C) 2017 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only import QtQuick import QtTest @@ -20,7 +20,12 @@ TestCase { Component { id: tabBar - TabBar { } + TabBar { + topPadding: 0 + bottomPadding: 0 + leftPadding: 0 + rightPadding: 0 + } } Component { @@ -53,10 +58,12 @@ TestCase { SignalSpy { } } - function test_defaults() { + function init() { failOnWarning(/.?/) + } - var control = createTemporaryObject(tabBar, testCase) + function test_defaults() { + let control = createTemporaryObject(tabBar, testCase) verify(control) compare(control.count, 0) compare(control.currentIndex, -1) @@ -64,7 +71,7 @@ TestCase { } function test_current() { - var control = createTemporaryObject(tabBar, testCase) + let control = createTemporaryObject(tabBar, testCase) compare(control.count, 0) compare(control.currentIndex, -1) @@ -110,7 +117,7 @@ TestCase { } function test_current_static() { - var control = createTemporaryObject(tabBarStaticTabs, testCase) + let control = createTemporaryObject(tabBarStaticTabs, testCase) compare(control.count, 2) compare(control.currentIndex, 0) @@ -126,7 +133,7 @@ TestCase { } function test_addRemove() { - var control = createTemporaryObject(tabBar, testCase) + let control = createTemporaryObject(tabBar, testCase) function verifyCurrentIndexCountDiff() { verify(control.currentIndex < control.count) @@ -134,7 +141,7 @@ TestCase { control.currentIndexChanged.connect(verifyCurrentIndexCountDiff) control.countChanged.connect(verifyCurrentIndexCountDiff) - var contentChildrenSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "contentChildrenChanged"}) + let contentChildrenSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "contentChildrenChanged"}) verify(contentChildrenSpy.valid) compare(control.count, 0) @@ -226,7 +233,7 @@ TestCase { } function test_removeCurrent() { - var control = createTemporaryObject(tabBar, testCase) + let control = createTemporaryObject(tabBar, testCase) control.addItem(tabButton.createObject(control, {text: "1"})) control.addItem(tabButton.createObject(control, {text: "2"})) @@ -260,19 +267,19 @@ TestCase { } function test_content() { - var control = createTemporaryObject(contentBar, testCase) + let control = createTemporaryObject(contentBar, testCase) function compareObjectNames(content, names) { if (content.length !== names.length) return false - for (var i = 0; i < names.length; ++i) { + for (let i = 0; i < names.length; ++i) { if (content[i].objectName !== names[i]) return false } return true } - var contentChildrenSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "contentChildrenChanged"}) + let contentChildrenSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "contentChildrenChanged"}) verify(contentChildrenSpy.valid) verify(compareObjectNames(control.contentData, ["object", "button1", "timer", "button2", ""])) @@ -312,20 +319,20 @@ TestCase { } function test_repeater() { - var control = createTemporaryObject(repeated, testCase) + let control = createTemporaryObject(repeated, testCase) verify(control) - var model = control.contentModel + let model = control.contentModel verify(model) - var repeater = control.repeater + let repeater = control.repeater verify(repeater) compare(repeater.count, 5) compare(model.count, 5) - for (var i = 0; i < 5; ++i) { - var item1 = control.itemAt(i) + for (let i = 0; i < 5; ++i) { + let item1 = control.itemAt(i) verify(item1) compare(item1.idx, i) compare(model.get(i), item1) @@ -336,8 +343,8 @@ TestCase { compare(repeater.count, 3) compare(model.count, 3) - for (var j = 0; j < 3; ++j) { - var item2 = control.itemAt(j) + for (let j = 0; j < 3; ++j) { + let item2 = control.itemAt(j) verify(item2) compare(item2.idx, j) compare(model.get(j), item2) @@ -366,7 +373,7 @@ TestCase { } function test_order() { - var control = createTemporaryObject(ordered, testCase) + let control = createTemporaryObject(ordered, testCase) verify(control) compare(control.count, 7) @@ -415,12 +422,12 @@ TestCase { } function test_move(data) { - var control = createTemporaryObject(tabBar, testCase) + let control = createTemporaryObject(tabBar, testCase) compare(control.count, 0) - var titles = ["1", "2", "3"] + let titles = ["1", "2", "3"] - var i = 0; + let i = 0; for (i = 0; i < titles.length; ++i) control.addItem(tabButton.createObject(control, {text: titles[i]})) @@ -434,7 +441,7 @@ TestCase { compare(control.count, titles.length) compare(control.currentIndex, data.currentAfter) - var title = titles[data.from] + let title = titles[data.from] titles.splice(data.from, 1) titles.splice(data.to, 0, title) @@ -457,13 +464,13 @@ TestCase { } function test_dynamic() { - var control = createTemporaryObject(dynamicBar, testCase) + let control = createTemporaryObject(dynamicBar, testCase) // insertItem(), addItem(), createObject() and static TabButton {} compare(control.count, 4) compare(control.itemAt(0).text, "inserted") - var tab = tabButton.createObject(control, {text: "dying"}) + let tab = tabButton.createObject(control, {text: "dying"}) compare(control.count, 5) compare(control.itemAt(4).text, "dying") @@ -482,13 +489,13 @@ TestCase { } function test_layout(data) { - var control = createTemporaryObject(tabBar, testCase, {spacing: data.spacing, width: 200}) + let control = createTemporaryObject(tabBar, testCase, {spacing: data.spacing, width: 200}) // remove the background so that it won't affect the implicit size of the tabbar, // so the implicit sizes tested below are entirely based on the content size control.background = null - var tab1 = tabButton.createObject(control, {text: "First"}) + let tab1 = tabButton.createObject(control, {text: "First"}) control.addItem(tab1) tryCompare(tab1, "width", control.width) compare(tab1.height, control.height) @@ -499,7 +506,7 @@ TestCase { compare(control.implicitWidth, control.contentWidth + control.leftPadding + control.rightPadding) compare(control.implicitHeight, control.contentHeight + control.topPadding + control.bottomPadding) - var tab2 = tabButton.createObject(control, {implicitHeight: tab1.implicitHeight + 10, text: "Second"}) + let tab2 = tabButton.createObject(control, {implicitHeight: tab1.implicitHeight + 10, text: "Second"}) control.addItem(tab2) tryCompare(tab1, "width", (control.width - data.spacing) / 2) compare(tab1.height, control.height) @@ -512,7 +519,7 @@ TestCase { compare(control.implicitWidth, control.contentWidth + control.leftPadding + control.rightPadding) compare(control.implicitHeight, control.contentHeight + control.topPadding + control.bottomPadding) - var tab3 = tabButton.createObject(control, {width: 50, height: tab1.implicitHeight - 10, text: "Third"}) + let tab3 = tabButton.createObject(control, {width: 50, height: tab1.implicitHeight - 10, text: "Third"}) control.addItem(tab3) tryCompare(tab1, "width", (control.width - 2 * data.spacing - 50) / 2) compare(tab1.y, 0) @@ -531,7 +538,8 @@ TestCase { compare(control.implicitWidth, control.contentWidth + control.leftPadding + control.rightPadding) compare(control.implicitHeight, control.contentHeight + control.topPadding + control.bottomPadding) - var expectedWidth = tab3.contentItem.implicitWidth + tab3.leftPadding + tab3.rightPadding + let expectedWidth = Math.max(tab3.implicitBackgroundWidth + tab3.leftInset + tab3.rightInset, + tab3.implicitContentWidth + tab3.leftPadding + tab3.rightPadding) tab3.width = tab3.implicitWidth tab3.height = tab3.implicitHeight tryCompare(tab1, "width", (control.width - 2 * data.spacing - expectedWidth) / 2) @@ -621,10 +629,10 @@ TestCase { } function test_attached() { - var control = createTemporaryObject(tabBar, testCase, {position: TabBar.Footer}) + let control = createTemporaryObject(tabBar, testCase, {position: TabBar.Footer}) // append - var tab1 = createTemporaryObject(attachedButton, testCase) + let tab1 = createTemporaryObject(attachedButton, testCase) compare(tab1.index, -1) compare(tab1.tabBar, null) compare(tab1.position, TabBar.Header) @@ -635,7 +643,7 @@ TestCase { compare(tab1.position, TabBar.Footer) // insert in the beginning - var tab2 = createTemporaryObject(attachedButton, testCase) + let tab2 = createTemporaryObject(attachedButton, testCase) compare(tab2.index, -1) compare(tab2.tabBar, null) compare(tab2.position, TabBar.Header) @@ -648,7 +656,7 @@ TestCase { compare(tab1.index, 1) // insert in the middle - var tab3 = createTemporaryObject(attachedButton, testCase) + let tab3 = createTemporaryObject(attachedButton, testCase) compare(tab3.index, -1) compare(tab3.tabBar, null) compare(tab3.position, TabBar.Header) @@ -662,7 +670,7 @@ TestCase { compare(tab1.index, 2) // insert in the end - var tab4 = createTemporaryObject(attachedButton, testCase) + let tab4 = createTemporaryObject(attachedButton, testCase) compare(tab4.index, -1) compare(tab4.tabBar, null) compare(tab4.position, TabBar.Header) diff --git a/tests/auto/quickcontrols/controls/data/tst_tabbutton.qml b/tests/auto/quickcontrols/controls/data/tst_tabbutton.qml index 591622b8a2..1c6181a97f 100644 --- a/tests/auto/quickcontrols/controls/data/tst_tabbutton.qml +++ b/tests/auto/quickcontrols/controls/data/tst_tabbutton.qml @@ -1,5 +1,5 @@ // Copyright (C) 2017 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only import QtQuick import QtTest @@ -28,22 +28,24 @@ TestCase { } } - function test_defaults() { + function init() { failOnWarning(/.?/) + } + function test_defaults() { let control = createTemporaryObject(tabButton, testCase) verify(control) } function test_autoExclusive() { - var container = createTemporaryObject(repeater, testCase) + let container = createTemporaryObject(repeater, testCase) - for (var i = 0; i < 3; ++i) { + for (let i = 0; i < 3; ++i) { container.children[i].checked = true compare(container.children[i].checked, true) // check that all other buttons are unchecked - for (var j = 0; j < 3; ++j) { + for (let j = 0; j < 3; ++j) { if (j !== i) compare(container.children[j].checked, false) } @@ -51,18 +53,18 @@ TestCase { } function test_baseline() { - var control = createTemporaryObject(tabButton, testCase) + let control = createTemporaryObject(tabButton, testCase) verify(control) compare(control.baselineOffset, control.contentItem.y + control.contentItem.baselineOffset) } function test_spacing() { - var control = createTemporaryObject(tabButton, testCase, { text: "Some long, long, long text" }) + let control = createTemporaryObject(tabButton, testCase, { text: "Some long, long, long text" }) verify(control) if (control.background) verify(control.contentItem.implicitWidth + control.leftPadding + control.rightPadding > control.background.implicitWidth) - var textLabel = findChild(control.contentItem, "label") + let textLabel = findChild(control.contentItem, "label") verify(textLabel) // The implicitWidth of the IconLabel that all buttons use as their contentItem @@ -91,7 +93,7 @@ TestCase { } function test_display(data) { - var control = createTemporaryObject(tabButton, testCase, { + let control = createTemporaryObject(tabButton, testCase, { text: "TabButton", display: data.display, "icon.source": "qrc:/qt-project.org/imports/QtQuick/Controls/Basic/images/check.png", @@ -100,8 +102,8 @@ TestCase { verify(control) compare(control.icon.source, "qrc:/qt-project.org/imports/QtQuick/Controls/Basic/images/check.png") - var iconImage = findChild(control.contentItem, "image") - var textLabel = findChild(control.contentItem, "label") + let iconImage = findChild(control.contentItem, "image") + let textLabel = findChild(control.contentItem, "label") switch (control.display) { case TabButton.IconOnly: diff --git a/tests/auto/quickcontrols/controls/data/tst_textarea.qml b/tests/auto/quickcontrols/controls/data/tst_textarea.qml index 0f295905f1..5e28b6733f 100644 --- a/tests/auto/quickcontrols/controls/data/tst_textarea.qml +++ b/tests/auto/quickcontrols/controls/data/tst_textarea.qml @@ -1,9 +1,10 @@ // Copyright (C) 2017 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only import QtQuick import QtTest import QtQuick.Controls +import Qt.test.controls TestCase { id: testCase @@ -68,33 +69,35 @@ TestCase { id: util } - function test_creation() { + function init() { failOnWarning(/.?/) + } - var control = createTemporaryObject(textArea, testCase) + function test_creation() { + let control = createTemporaryObject(textArea, testCase) verify(control) } function test_implicitSize() { - var control = createTemporaryObject(textArea, testCase) + let control = createTemporaryObject(textArea, testCase) verify(control) - var implicitWidthSpy = signalSpy.createObject(control, { target: control, signalName: "implicitWidthChanged"} ) + let implicitWidthSpy = signalSpy.createObject(control, { target: control, signalName: "implicitWidthChanged"} ) verify(implicitWidthSpy.valid) - var implicitHeightSpy = signalSpy.createObject(control, { target: control, signalName: "implicitHeightChanged"} ) + let implicitHeightSpy = signalSpy.createObject(control, { target: control, signalName: "implicitHeightChanged"} ) verify(implicitHeightSpy.valid) - var implicitBackgroundWidthSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "implicitBackgroundWidthChanged"}) + let implicitBackgroundWidthSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "implicitBackgroundWidthChanged"}) verify(implicitBackgroundWidthSpy.valid) - var implicitBackgroundHeightSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "implicitBackgroundHeightChanged"}) + let implicitBackgroundHeightSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "implicitBackgroundHeightChanged"}) verify(implicitBackgroundHeightSpy.valid) - var implicitWidthChanges = 0 - var implicitHeightChanges = 0 - var implicitBackgroundWidthChanges = 0 - var implicitBackgroundHeightChanges = 0 + let implicitWidthChanges = 0 + let implicitHeightChanges = 0 + let implicitBackgroundWidthChanges = 0 + let implicitBackgroundHeightChanges = 0 verify(control.implicitWidth >= control.leftPadding + control.rightPadding) verify(control.implicitHeight >= control.contentHeight + control.topPadding + control.bottomPadding) @@ -129,11 +132,11 @@ TestCase { compare(implicitWidthSpy.count, ++implicitWidthChanges) defaultFontMetrics.font = control.font - var leading = defaultFontMetrics.leading - var ascent = defaultFontMetrics.ascent - var descent = defaultFontMetrics.descent + let leading = defaultFontMetrics.leading + let ascent = defaultFontMetrics.ascent + let descent = defaultFontMetrics.descent - var leadingOverflow = Math.ceil(ascent + descent) < Math.ceil(ascent + descent + leading) + let leadingOverflow = Math.ceil(ascent + descent) < Math.ceil(ascent + descent + leading) // If the font in use triggers QTBUG-83894, it is possible that this will cause // the following compare to fail if the implicitHeight from the TextEdit is ued. @@ -206,20 +209,28 @@ TestCase { } function test_alignment(data) { - var control = createTemporaryObject(textArea, testCase, {text: data.text, placeholderText: data.placeholderText, horizontalAlignment: data.textAlignment}) + let control = createTemporaryObject(textArea, testCase, {text: data.text, placeholderText: data.placeholderText}) - if (data.textAlignment !== undefined) + if (data.textAlignment !== undefined) { + control.horizontalAlignment = data.textAlignment compare(control.horizontalAlignment, data.textAlignment) - for (var i = 0; i < control.children.length; ++i) { - if (control.children[i].hasOwnProperty("horizontalAlignment")) - compare(control.children[i].effectiveHorizontalAlignment, data.placeholderAlignment) // placeholder + } + + // The placeholder text of the Material style doesn't currently respect the alignment of the control. + if (StyleInfo.styleName !== "Material") { + for (let i = 0; i < control.children.length; ++i) { + if (control.children[i].hasOwnProperty("horizontalAlignment")) + compare(control.children[i].effectiveHorizontalAlignment, data.placeholderAlignment) // placeholder + } } control.verticalAlignment = TextArea.AlignBottom compare(control.verticalAlignment, TextArea.AlignBottom) - for (var j = 0; j < control.children.length; ++j) { - if (control.children[j].hasOwnProperty("verticalAlignment")) - compare(control.children[j].verticalAlignment, Text.AlignBottom) // placeholder + if (StyleInfo.styleName !== "Material") { + for (let j = 0; j < control.children.length; ++j) { + if (control.children[j].hasOwnProperty("verticalAlignment")) + compare(control.children[j].verticalAlignment, Text.AlignBottom) // placeholder + } } } @@ -227,7 +238,7 @@ TestCase { return [ {tag: "bold", value: true}, {tag: "capitalization", value: Font.Capitalize}, - {tag: "family", value: "Courier"}, + {tag: "family", value: "Tahoma"}, {tag: "italic", value: true}, {tag: "strikeout", value: true}, {tag: "underline", value: true}, @@ -237,19 +248,19 @@ TestCase { } function test_font_explicit_attributes(data) { - var control = createTemporaryObject(textArea, testCase) + let control = createTemporaryObject(textArea, testCase) verify(control) - var child = textArea.createObject(control) + let child = textArea.createObject(control) verify(child) - var controlSpy = signalSpy.createObject(control, {target: control, signalName: "fontChanged"}) + let controlSpy = signalSpy.createObject(control, {target: control, signalName: "fontChanged"}) verify(controlSpy.valid) - var childSpy = signalSpy.createObject(child, {target: child, signalName: "fontChanged"}) + let childSpy = signalSpy.createObject(child, {target: child, signalName: "fontChanged"}) verify(childSpy.valid) - var defaultValue = control.font[data.tag] + let defaultValue = control.font[data.tag] child.font[data.tag] = defaultValue compare(child.font[data.tag], defaultValue) @@ -265,33 +276,33 @@ TestCase { } function test_flickable() { - var control = createTemporaryObject(flickable, testCase, {text:"line0", selectByMouse: true}) + let control = createTemporaryObject(flickable, testCase) verify(control) - var textArea = control.TextArea.flickable + let textArea = control.TextArea.flickable verify(textArea) if (textArea.background) compare(textArea.background.parent, control) - for (var i = 1; i <= 100; ++i) + for (let i = 1; i <= 100; ++i) textArea.text += "line\n" + i verify(textArea.contentWidth > 0) verify(textArea.contentHeight > 200) - compare(control.contentWidth, textArea.contentWidth + textArea.leftPadding + textArea.rightPadding) - compare(control.contentHeight, textArea.contentHeight + textArea.topPadding + textArea.bottomPadding) + compare(control.contentWidth, textArea.implicitWidth) + compare(control.contentHeight, textArea.implicitHeight) compare(textArea.cursorPosition, 0) - var center = textArea.positionAt(control.width / 2, control.height / 2) + let center = textArea.positionAt(control.width / 2, control.height / 2) verify(center > 0) mouseClick(textArea, control.width / 2, control.height / 2) compare(textArea.cursorPosition, center) // click inside text area, but below flickable - var below = textArea.positionAt(control.width / 2, control.height + 1) + let below = textArea.positionAt(control.width / 2, control.height + 1) verify(below > center) mouseClick(textArea, control.width / 2, control.height + 1) compare(textArea.cursorPosition, center) // no change @@ -300,7 +311,7 @@ TestCase { control.contentY = -(control.contentHeight - control.height) / 2 // click inside textarea, but above flickable - var above = textArea.positionAt(control.width / 2, textArea.topPadding) + let above = textArea.positionAt(control.width / 2, textArea.topPadding) verify(above > 0 && above < center) mouseClick(textArea, control.width / 2, 0) compare(textArea.cursorPosition, center) // no change @@ -310,10 +321,10 @@ TestCase { // Test that the TextArea background item is parented out of the // TextArea and into the Flicable, and that it has the same size // as the flickable. - var flickable = createTemporaryObject(flickableCustomBackground, testCase) + let flickable = createTemporaryObject(flickableCustomBackground, testCase) verify(flickable) - var textArea = flickable.TextArea.flickable + let textArea = flickable.TextArea.flickable verify(textArea) verify(textArea.background) compare(textArea.background.width, flickable.width) @@ -321,10 +332,10 @@ TestCase { } function test_scrollable_paste_large() { - var control = createTemporaryObject(flickableWithScrollBar, testCase) + let control = createTemporaryObject(flickableWithScrollBar, testCase) verify(control) - var textArea = control.TextArea.flickable + let textArea = control.TextArea.flickable verify(textArea) if (typeof(textArea.paste) !== "function") @@ -352,7 +363,7 @@ TestCase { } function test_hover(data) { - var control = createTemporaryObject(textArea, testCase, {text: "TextArea", hoverEnabled: data.hoverEnabled}) + let control = createTemporaryObject(textArea, testCase, {text: "TextArea", hoverEnabled: data.hoverEnabled}) verify(control) compare(control.hovered, false) @@ -417,9 +428,9 @@ TestCase { } function test_pressedReleased(data) { - var mouseArea = createTemporaryObject(mouseAreaComponent, testCase) + let mouseArea = createTemporaryObject(mouseAreaComponent, testCase) verify(mouseArea) - var control = textArea.createObject(mouseArea, {text: "TextArea"}) + let control = textArea.createObject(mouseArea, {text: "TextArea"}) verify(control) // Give enough room to check presses outside of the control and on the parent. @@ -449,13 +460,13 @@ TestCase { if (data.parentReleaseEvent) control.onReleased.connect(checkParentReleaseEvent) - var controlPressedSpy = signalSpy.createObject(control, { target: control, signalName: "pressed" }) + let controlPressedSpy = signalSpy.createObject(control, { target: control, signalName: "pressed" }) verify(controlPressedSpy.valid) - var controlReleasedSpy = signalSpy.createObject(control, { target: control, signalName: "released" }) + let controlReleasedSpy = signalSpy.createObject(control, { target: control, signalName: "released" }) verify(controlReleasedSpy.valid) - var parentPressedSpy = signalSpy.createObject(mouseArea, { target: mouseArea, signalName: "pressed" }) + let parentPressedSpy = signalSpy.createObject(mouseArea, { target: mouseArea, signalName: "pressed" }) verify(parentPressedSpy.valid) - var parentReleasedSpy = signalSpy.createObject(mouseArea, { target: mouseArea, signalName: "released" }) + let parentReleasedSpy = signalSpy.createObject(mouseArea, { target: mouseArea, signalName: "released" }) verify(parentReleasedSpy.valid) mousePress(control, data.x, data.y, data.button) @@ -473,8 +484,8 @@ TestCase { property bool ignorePress: false property bool ignoreRelease: false - onPressed: if (ignorePress) event.accepted = false - onReleased: if (ignoreRelease) event.accepted = false + onPressed: function (event) { if (ignorePress) event.accepted = false } + onReleased: function (event) { if (ignoreRelease) event.accepted = false } } } @@ -487,18 +498,18 @@ TestCase { } function test_ignorePressRelease() { - var mouseArea = createTemporaryObject(mouseAreaComponent, testCase) + let mouseArea = createTemporaryObject(mouseAreaComponent, testCase) verify(mouseArea) - var control = ignoreTextArea.createObject(mouseArea) + let control = ignoreTextArea.createObject(mouseArea) verify(control) - var controlPressedSpy = signalSpy.createObject(control, { target: control, signalName: "pressed" }) + let controlPressedSpy = signalSpy.createObject(control, { target: control, signalName: "pressed" }) verify(controlPressedSpy.valid) - var controlReleasedSpy = signalSpy.createObject(control, { target: control, signalName: "released" }) + let controlReleasedSpy = signalSpy.createObject(control, { target: control, signalName: "released" }) verify(controlReleasedSpy.valid) - var parentPressedSpy = signalSpy.createObject(mouseArea, { target: mouseArea, signalName: "pressed" }) + let parentPressedSpy = signalSpy.createObject(mouseArea, { target: mouseArea, signalName: "pressed" }) verify(parentPressedSpy.valid) - var parentReleasedSpy = signalSpy.createObject(mouseArea, { target: mouseArea, signalName: "released" }) + let parentReleasedSpy = signalSpy.createObject(mouseArea, { target: mouseArea, signalName: "released" }) verify(parentReleasedSpy.valid) // Ignore only press events. @@ -529,12 +540,12 @@ TestCase { } function test_multiClick() { - var control = createTemporaryObject(textArea, testCase, {text: "Qt Quick Controls 2 TextArea", selectByMouse: true}) + let control = createTemporaryObject(textArea, testCase, {text: "Qt Quick Controls 2 TextArea", selectByMouse: true}) verify(control) waitForRendering(control) control.width = control.contentWidth - var rect = control.positionToRectangle(12) + let rect = control.positionToRectangle(12) // double click -> select word mouseDoubleClickSequence(control, rect.x + rect.width / 2, rect.y + rect.height / 2) @@ -553,7 +564,7 @@ TestCase { } function test_scrollView() { - var control = createTemporaryObject(scrollView, testCase) + let control = createTemporaryObject(scrollView, testCase) verify(control) // don't crash (QTBUG-62292) @@ -562,7 +573,7 @@ TestCase { } function test_placeholderTextColor() { - var control = createTemporaryObject(textArea, testCase) + let control = createTemporaryObject(textArea, testCase) verify(control) // usually default value should not be pure opacue black @@ -570,32 +581,32 @@ TestCase { control.placeholderTextColor = "#12345678" compare(control.placeholderTextColor, "#12345678") - for (var i = 0; i < control.children.length; ++i) { + for (let i = 0; i < control.children.length; ++i) { if (control.children[i].hasOwnProperty("text")) compare(control.children[i].color, control.placeholderTextColor) // placeholder.color } } function test_inset() { - var control = createTemporaryObject(textArea, testCase, {background: rectangle.createObject(control)}) + let control = createTemporaryObject(textArea, testCase, {background: rectangle.createObject(testCase)}) verify(control) - var topInsetSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "topInsetChanged"}) + let topInsetSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "topInsetChanged"}) verify(topInsetSpy.valid) - var leftInsetSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "leftInsetChanged"}) + let leftInsetSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "leftInsetChanged"}) verify(leftInsetSpy.valid) - var rightInsetSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "rightInsetChanged"}) + let rightInsetSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "rightInsetChanged"}) verify(rightInsetSpy.valid) - var bottomInsetSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "bottomInsetChanged"}) + let bottomInsetSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "bottomInsetChanged"}) verify(bottomInsetSpy.valid) - var topInsetChanges = 0 - var leftInsetChanges = 0 - var rightInsetChanges = 0 - var bottomInsetChanges = 0 + let topInsetChanges = 0 + let leftInsetChanges = 0 + let rightInsetChanges = 0 + let bottomInsetChanges = 0 compare(control.topInset, 0) compare(control.leftInset, 0) @@ -756,7 +767,7 @@ TestCase { } function test_resize_background() { - var control = createTemporaryObject(testResizeBackground, testCase) + let control = createTemporaryObject(testResizeBackground, testCase) compare(control.textArea.background.width, control.width) compare(control.textArea.background.height, 1) diff --git a/tests/auto/quickcontrols/controls/data/tst_textfield.qml b/tests/auto/quickcontrols/controls/data/tst_textfield.qml index f5b3d91fe1..ef1cca71b5 100644 --- a/tests/auto/quickcontrols/controls/data/tst_textfield.qml +++ b/tests/auto/quickcontrols/controls/data/tst_textfield.qml @@ -1,10 +1,11 @@ // Copyright (C) 2017 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only import QtQuick import QtTest import QtQuick.Controls import QtQuick.Layouts +import Qt.test.controls TestCase { id: testCase @@ -29,33 +30,35 @@ TestCase { SignalSpy { } } - function test_creation() { + function init() { failOnWarning(/.?/) + } - var control = createTemporaryObject(textField, testCase) + function test_creation() { + let control = createTemporaryObject(textField, testCase) verify(control) } function test_implicitSize() { - var control = createTemporaryObject(textField, testCase) + let control = createTemporaryObject(textField, testCase) verify(control) - var implicitWidthSpy = signalSpy.createObject(control, { target: control, signalName: "implicitWidthChanged"} ) + let implicitWidthSpy = signalSpy.createObject(control, { target: control, signalName: "implicitWidthChanged"} ) verify(implicitWidthSpy.valid) - var implicitHeightSpy = signalSpy.createObject(control, { target: control, signalName: "implicitHeightChanged"} ) + let implicitHeightSpy = signalSpy.createObject(control, { target: control, signalName: "implicitHeightChanged"} ) verify(implicitHeightSpy.valid) - var implicitBackgroundWidthSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "implicitBackgroundWidthChanged"}) + let implicitBackgroundWidthSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "implicitBackgroundWidthChanged"}) verify(implicitBackgroundWidthSpy.valid) - var implicitBackgroundHeightSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "implicitBackgroundHeightChanged"}) + let implicitBackgroundHeightSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "implicitBackgroundHeightChanged"}) verify(implicitBackgroundHeightSpy.valid) - var implicitWidthChanges = 0 - var implicitHeightChanges = 0 - var implicitBackgroundWidthChanges = 0 - var implicitBackgroundHeightChanges = 0 + let implicitWidthChanges = 0 + let implicitHeightChanges = 0 + let implicitBackgroundWidthChanges = 0 + let implicitBackgroundHeightChanges = 0 verify(control.implicitWidth >= control.leftPadding + control.rightPadding) verify(control.implicitHeight >= control.contentHeight + control.topPadding + control.bottomPadding) @@ -153,20 +156,27 @@ TestCase { } function test_alignment(data) { - var control = createTemporaryObject(textField, testCase, {text: data.text, placeholderText: data.placeholderText, horizontalAlignment: data.textAlignment}) + let control = createTemporaryObject(textField, testCase, {text: data.text, placeholderText: data.placeholderText}) - if (data.textAlignment !== undefined) + if (data.textAlignment !== undefined) { + control.horizontalAlignment = data.textAlignment compare(control.horizontalAlignment, data.textAlignment) - for (var i = 0; i < control.children.length; ++i) { - if (control.children[i].hasOwnProperty("text") && control.children[i].hasOwnProperty("horizontalAlignment")) - compare(control.children[i].effectiveHorizontalAlignment, data.placeholderAlignment) // placeholder + } + // The placeholder text of the Material style doesn't currently respect the alignment of the control. + if (StyleInfo.styleName !== "Material") { + for (let i = 0; i < control.children.length; ++i) { + if (control.children[i].hasOwnProperty("text") && control.children[i].hasOwnProperty("horizontalAlignment")) + compare(control.children[i].effectiveHorizontalAlignment, data.placeholderAlignment) // placeholder + } } control.verticalAlignment = TextField.AlignBottom compare(control.verticalAlignment, TextField.AlignBottom) - for (var j = 0; j < control.children.length; ++j) { - if (control.children[j].hasOwnProperty("text") && control.children[j].hasOwnProperty("verticalAlignment")) - compare(control.children[j].verticalAlignment, Text.AlignBottom) // placeholder + if (StyleInfo.styleName !== "Material") { + for (let j = 0; j < control.children.length; ++j) { + if (control.children[j].hasOwnProperty("text") && control.children[j].hasOwnProperty("verticalAlignment")) + compare(control.children[j].verticalAlignment, Text.AlignBottom) // placeholder + } } } @@ -174,7 +184,7 @@ TestCase { return [ {tag: "bold", value: true}, {tag: "capitalization", value: Font.Capitalize}, - {tag: "family", value: "Courier"}, + {tag: "family", value: "Tahoma"}, {tag: "italic", value: true}, {tag: "strikeout", value: true}, {tag: "underline", value: true}, @@ -184,19 +194,19 @@ TestCase { } function test_font_explicit_attributes(data) { - var control = createTemporaryObject(textField, testCase) + let control = createTemporaryObject(textField, testCase) verify(control) - var child = textField.createObject(control) + let child = textField.createObject(control) verify(child) - var controlSpy = signalSpy.createObject(control, {target: control, signalName: "fontChanged"}) + let controlSpy = signalSpy.createObject(control, {target: control, signalName: "fontChanged"}) verify(controlSpy.valid) - var childSpy = signalSpy.createObject(child, {target: child, signalName: "fontChanged"}) + let childSpy = signalSpy.createObject(child, {target: child, signalName: "fontChanged"}) verify(childSpy.valid) - var defaultValue = control.font[data.tag] + let defaultValue = control.font[data.tag] child.font[data.tag] = defaultValue compare(child.font[data.tag], defaultValue) @@ -219,7 +229,7 @@ TestCase { } function test_hover(data) { - var control = createTemporaryObject(textField, testCase, {hoverEnabled: data.hoverEnabled}) + let control = createTemporaryObject(textField, testCase, {hoverEnabled: data.hoverEnabled}) verify(control) compare(control.hovered, false) @@ -284,9 +294,9 @@ TestCase { } function test_pressedReleased(data) { - var mouseArea = createTemporaryObject(mouseAreaComponent, testCase) + let mouseArea = createTemporaryObject(mouseAreaComponent, testCase) verify(mouseArea) - var control = textField.createObject(mouseArea) + let control = textField.createObject(mouseArea) verify(control) // Give enough room to check presses outside of the control and on the parent. @@ -316,13 +326,13 @@ TestCase { if (data.parentReleaseEvent) control.onReleased.connect(checkParentReleaseEvent) - var controlPressedSpy = signalSpy.createObject(control, { target: control, signalName: "pressed" }) + let controlPressedSpy = signalSpy.createObject(control, { target: control, signalName: "pressed" }) verify(controlPressedSpy.valid) - var controlReleasedSpy = signalSpy.createObject(control, { target: control, signalName: "released" }) + let controlReleasedSpy = signalSpy.createObject(control, { target: control, signalName: "released" }) verify(controlReleasedSpy.valid) - var parentPressedSpy = signalSpy.createObject(mouseArea, { target: mouseArea, signalName: "pressed" }) + let parentPressedSpy = signalSpy.createObject(mouseArea, { target: mouseArea, signalName: "pressed" }) verify(parentPressedSpy.valid) - var parentReleasedSpy = signalSpy.createObject(mouseArea, { target: mouseArea, signalName: "released" }) + let parentReleasedSpy = signalSpy.createObject(mouseArea, { target: mouseArea, signalName: "released" }) verify(parentReleasedSpy.valid) mousePress(control, data.x, data.y, data.button) @@ -340,8 +350,8 @@ TestCase { property bool ignorePress: false property bool ignoreRelease: false - onPressed: if (ignorePress) event.accepted = false - onReleased: if (ignoreRelease) event.accepted = false + onPressed: function (event) { if (ignorePress) event.accepted = false } + onReleased: function (event) { if (ignoreRelease) event.accepted = false } } } @@ -354,18 +364,18 @@ TestCase { } function test_ignorePressRelease() { - var mouseArea = createTemporaryObject(mouseAreaComponent, testCase) + let mouseArea = createTemporaryObject(mouseAreaComponent, testCase) verify(mouseArea) - var control = ignoreTextField.createObject(mouseArea) + let control = ignoreTextField.createObject(mouseArea) verify(control) - var controlPressedSpy = signalSpy.createObject(control, { target: control, signalName: "pressed" }) + let controlPressedSpy = signalSpy.createObject(control, { target: control, signalName: "pressed" }) verify(controlPressedSpy.valid) - var controlReleasedSpy = signalSpy.createObject(control, { target: control, signalName: "released" }) + let controlReleasedSpy = signalSpy.createObject(control, { target: control, signalName: "released" }) verify(controlReleasedSpy.valid) - var parentPressedSpy = signalSpy.createObject(mouseArea, { target: mouseArea, signalName: "pressed" }) + let parentPressedSpy = signalSpy.createObject(mouseArea, { target: mouseArea, signalName: "pressed" }) verify(parentPressedSpy.valid) - var parentReleasedSpy = signalSpy.createObject(mouseArea, { target: mouseArea, signalName: "released" }) + let parentReleasedSpy = signalSpy.createObject(mouseArea, { target: mouseArea, signalName: "released" }) verify(parentReleasedSpy.valid) // Ignore only press events. @@ -396,12 +406,12 @@ TestCase { } function test_multiClick() { - var control = createTemporaryObject(textField, testCase, {text: "Qt Quick Controls 2 TextArea"}) + let control = createTemporaryObject(textField, testCase, {text: "Qt Quick Controls 2 TextArea"}) verify(control) waitForRendering(control) control.width = control.contentWidth - var rect = control.positionToRectangle(12) + let rect = control.positionToRectangle(12) // double click -> select word mouseDoubleClickSequence(control, rect.x + rect.width / 2, rect.y + rect.height / 2) @@ -414,7 +424,7 @@ TestCase { // QTBUG-64048 function test_rightClick() { - var control = createTemporaryObject(textField, testCase, {text: "TextField"}) + let control = createTemporaryObject(textField, testCase, {text: "TextField"}) verify(control) control.selectAll() @@ -428,10 +438,10 @@ TestCase { } function test_mouseSelect() { - var control = createTemporaryObject(textField, testCase, {text: "Text", width: parent.width}) + let control = createTemporaryObject(textField, testCase, {text: "Text", width: parent.width}) verify(control) verify(control.selectByMouse) // true by default since 6.4 - var pressSpy = signalSpy.createObject(control, {target: control, signalName: "pressed"}) + let pressSpy = signalSpy.createObject(control, {target: control, signalName: "pressed"}) const y = control.height / 2 mousePress(control, 0, y, Qt.LeftButton) @@ -442,11 +452,11 @@ TestCase { } function test_noTouchSelect() { - var control = createTemporaryObject(textField, testCase, {text: "Text"}) + let control = createTemporaryObject(textField, testCase, {text: "Text"}) verify(control) verify(control.selectByMouse) // true by default since 6.4 - var touch = touchEvent(control) + let touch = touchEvent(control) const y = control.height / 2 touch.press(0, control, 0, y).commit() touch.move(0, control, control.implicitWidth, 0).commit() @@ -455,13 +465,13 @@ TestCase { } function test_aaTouchPressAndHold() { - var control = createTemporaryObject(textField, testCase, {text: "Text"}) + let control = createTemporaryObject(textField, testCase, {text: "Text"}) verify(control) verify(control.selectByMouse) // true by default since 6.4 - var pressSpy = signalSpy.createObject(control, {target: control, signalName: "pressed"}) - var pressAndHoldSpy = signalSpy.createObject(control, {target: control, signalName: "pressAndHold"}) + let pressSpy = signalSpy.createObject(control, {target: control, signalName: "pressed"}) + let pressAndHoldSpy = signalSpy.createObject(control, {target: control, signalName: "pressAndHold"}) - var touch = touchEvent(control) + let touch = touchEvent(control) touch.press(0, control).commit() tryCompare(pressSpy, "count", 1) tryCompare(pressAndHoldSpy, "count", 1) @@ -470,7 +480,7 @@ TestCase { // QTBUG-66260 function test_placeholderTextColor() { - var control = createTemporaryObject(textField, testCase) + let control = createTemporaryObject(textField, testCase) verify(control) // usually default value should not be pure opacue black @@ -478,32 +488,32 @@ TestCase { control.placeholderTextColor = "#12345678" compare(control.placeholderTextColor, "#12345678") - for (var i = 0; i < control.children.length; ++i) { + for (let i = 0; i < control.children.length; ++i) { if (control.children[i].hasOwnProperty("text")) compare(control.children[i].color, control.placeholderTextColor) // placeholder.color } } function test_inset() { - var control = createTemporaryObject(textField, testCase, {background: rectangle.createObject(control)}) + let control = createTemporaryObject(textField, testCase, {background: rectangle.createObject(testCase)}) verify(control) - var topInsetSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "topInsetChanged"}) + let topInsetSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "topInsetChanged"}) verify(topInsetSpy.valid) - var leftInsetSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "leftInsetChanged"}) + let leftInsetSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "leftInsetChanged"}) verify(leftInsetSpy.valid) - var rightInsetSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "rightInsetChanged"}) + let rightInsetSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "rightInsetChanged"}) verify(rightInsetSpy.valid) - var bottomInsetSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "bottomInsetChanged"}) + let bottomInsetSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "bottomInsetChanged"}) verify(bottomInsetSpy.valid) - var topInsetChanges = 0 - var leftInsetChanges = 0 - var rightInsetChanges = 0 - var bottomInsetChanges = 0 + let topInsetChanges = 0 + let leftInsetChanges = 0 + let rightInsetChanges = 0 + let bottomInsetChanges = 0 compare(control.topInset, 0) compare(control.leftInset, 0) @@ -647,10 +657,10 @@ TestCase { } function test_inLayout() { - var layout = createTemporaryObject(layoutComponent, testCase) + let layout = createTemporaryObject(layoutComponent, testCase) verify(layout) - var control = layout.textField + let control = layout.textField verify(control) compare(control.width, control.parent.width) @@ -676,14 +686,12 @@ TestCase { // macOS is special: 43eca45b061fe965fe2a6f1876d4a35a58e3a9e4 if (Qt.platform.os === "osx" || Qt.platform.os === "macos") skip("TextField hard-codes pixel size on macOS") - failOnWarning("Both point size and pixel size set. Using pixel size.") - var textField = createTemporaryObject(textFieldWithPointSizeSet, testCase) + let textField = createTemporaryObject(textFieldWithPointSizeSet, testCase) verify(textField) } function test_setPixelSizeDoesNotWarn() { - failOnWarning("Both point size and pixel size set. Using pixel size.") - var textField = createTemporaryObject(textFieldWithPixelSizeSet, testCase) + let textField = createTemporaryObject(textFieldWithPixelSizeSet, testCase) verify(textField) } } diff --git a/tests/auto/quickcontrols/controls/data/tst_toolbar.qml b/tests/auto/quickcontrols/controls/data/tst_toolbar.qml index d2c9e4a20d..e6be264a03 100644 --- a/tests/auto/quickcontrols/controls/data/tst_toolbar.qml +++ b/tests/auto/quickcontrols/controls/data/tst_toolbar.qml @@ -1,5 +1,5 @@ // Copyright (C) 2017 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only import QtQuick import QtTest @@ -52,10 +52,12 @@ TestCase { } } - function test_empty() { + function init() { failOnWarning(/.?/) + } - var control = createTemporaryObject(toolBar, testCase) + function test_empty() { + let control = createTemporaryObject(toolBar, testCase) verify(control) verify(control.contentItem) @@ -66,7 +68,7 @@ TestCase { } function test_oneChild() { - var control = createTemporaryObject(oneChildBar, testCase) + let control = createTemporaryObject(oneChildBar, testCase) verify(control) compare(control.contentWidth, 100) @@ -78,7 +80,7 @@ TestCase { } function test_twoChildren() { - var control = createTemporaryObject(twoChildrenBar, testCase) + let control = createTemporaryObject(twoChildrenBar, testCase) verify(control) compare(control.contentWidth, 0) @@ -90,7 +92,7 @@ TestCase { } function test_contentItem() { - var control = createTemporaryObject(contentBar, testCase) + let control = createTemporaryObject(contentBar, testCase) verify(control) compare(control.contentWidth, 100) diff --git a/tests/auto/quickcontrols/controls/data/tst_toolbutton.qml b/tests/auto/quickcontrols/controls/data/tst_toolbutton.qml index 4879e91611..2cf746d288 100644 --- a/tests/auto/quickcontrols/controls/data/tst_toolbutton.qml +++ b/tests/auto/quickcontrols/controls/data/tst_toolbutton.qml @@ -1,5 +1,5 @@ // Copyright (C) 2017 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only import QtQuick import QtTest @@ -23,15 +23,17 @@ TestCase { ToolButton { } } - function test_defaults() { + function init() { failOnWarning(/.?/) + } + function test_defaults() { let control = createTemporaryObject(toolButton, testCase) verify(control) } function test_text() { - var control = createTemporaryObject(toolButton, testCase) + let control = createTemporaryObject(toolButton, testCase) verify(control) compare(control.text, "") @@ -42,16 +44,16 @@ TestCase { } function test_mouse() { - var control = createTemporaryObject(toolButton, testCase) + let control = createTemporaryObject(toolButton, testCase) verify(control) - var pressedSpy = signalSpy.createObject(control, {target: control, signalName: "pressedChanged"}) + let pressedSpy = signalSpy.createObject(control, {target: control, signalName: "pressedChanged"}) verify(pressedSpy.valid) - var downSpy = signalSpy.createObject(control, {target: control, signalName: "downChanged"}) + let downSpy = signalSpy.createObject(control, {target: control, signalName: "downChanged"}) verify(downSpy.valid) - var clickedSpy = signalSpy.createObject(control, {target: control, signalName: "clicked"}) + let clickedSpy = signalSpy.createObject(control, {target: control, signalName: "clicked"}) verify(clickedSpy.valid) // check @@ -111,10 +113,10 @@ TestCase { } function test_keys() { - var control = createTemporaryObject(toolButton, testCase) + let control = createTemporaryObject(toolButton, testCase) verify(control) - var clickedSpy = signalSpy.createObject(control, {target: control, signalName: "clicked"}) + let clickedSpy = signalSpy.createObject(control, {target: control, signalName: "clicked"}) verify(clickedSpy.valid) control.forceActiveFocus() @@ -131,15 +133,15 @@ TestCase { // no change // Not testing Key_Enter and Key_Return because QGnomeTheme uses them for // pressing buttons and the CI uses the QGnomeTheme platform theme. - var keys = [Qt.Key_Escape, Qt.Key_Tab] - for (var i = 0; i < keys.length; ++i) { + let keys = [Qt.Key_Escape, Qt.Key_Tab] + for (let i = 0; i < keys.length; ++i) { keyClick(keys[i]) compare(clickedSpy.count, 2) } } function test_baseline() { - var control = createTemporaryObject(toolButton, testCase) + let control = createTemporaryObject(toolButton, testCase) verify(control) compare(control.baselineOffset, control.contentItem.y + control.contentItem.baselineOffset) } @@ -158,7 +160,7 @@ TestCase { } function test_display(data) { - var control = createTemporaryObject(toolButton, testCase, { + let control = createTemporaryObject(toolButton, testCase, { text: "ToolButton", display: data.display, "icon.source": "qrc:/qt-project.org/imports/QtQuick/Controls/Basic/images/check.png", @@ -167,8 +169,8 @@ TestCase { verify(control) compare(control.icon.source, "qrc:/qt-project.org/imports/QtQuick/Controls/Basic/images/check.png") - var iconImage = findChild(control.contentItem, "image") - var textLabel = findChild(control.contentItem, "label") + let iconImage = findChild(control.contentItem, "image") + let textLabel = findChild(control.contentItem, "label") switch (control.display) { case ToolButton.IconOnly: diff --git a/tests/auto/quickcontrols/controls/data/tst_toolseparator.qml b/tests/auto/quickcontrols/controls/data/tst_toolseparator.qml index ef7fc35758..f9ca5aec72 100644 --- a/tests/auto/quickcontrols/controls/data/tst_toolseparator.qml +++ b/tests/auto/quickcontrols/controls/data/tst_toolseparator.qml @@ -1,5 +1,5 @@ // Copyright (C) 2017 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only import QtQuick import QtTest @@ -17,15 +17,17 @@ TestCase { ToolSeparator {} } - function test_defaults() { + function init() { failOnWarning(/.?/) + } + function test_defaults() { let control = createTemporaryObject(toolSeparator, testCase) verify(control) } function test_size() { - var control = createTemporaryObject(toolSeparator, testCase); + let control = createTemporaryObject(toolSeparator, testCase); verify(control); verify(control.width > 1); verify(control.height > 1); @@ -37,15 +39,15 @@ TestCase { } function test_orientation() { - var control = createTemporaryObject(toolSeparator, testCase); + let control = createTemporaryObject(toolSeparator, testCase); verify(control); compare(control.horizontal, false); compare(control.vertical, true); - var orientationSpy = signalSpyComponent.createObject(control, { target: control, signalName: "orientationChanged" }); + let orientationSpy = signalSpyComponent.createObject(control, { target: control, signalName: "orientationChanged" }); - var originalWidth = control.width; - var originalHeight = control.height; + let originalWidth = control.width; + let originalHeight = control.height; control.orientation = Qt.Horizontal; compare(control.orientation, Qt.Horizontal); compare(control.width, originalHeight); diff --git a/tests/auto/quickcontrols/controls/data/tst_tooltip.qml b/tests/auto/quickcontrols/controls/data/tst_tooltip.qml index 1aa63e56a2..205536c61c 100644 --- a/tests/auto/quickcontrols/controls/data/tst_tooltip.qml +++ b/tests/auto/quickcontrols/controls/data/tst_tooltip.qml @@ -1,5 +1,5 @@ // Copyright (C) 2017 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only import QtQuick import QtTest @@ -37,9 +37,11 @@ TestCase { target: ToolTip.toolTip } - function test_defaults() { + function init() { failOnWarning(/.?/) + } + function test_defaults() { let control = createTemporaryObject(toolTip, testCase) verify(control) } @@ -53,12 +55,12 @@ TestCase { } function test_properties(data) { - var control = createTemporaryObject(toolTip, testCase) + let control = createTemporaryObject(toolTip, testCase) verify(control) compare(control[data.property], data.defaultValue) - var spy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: data.signalName}) + let spy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: data.signalName}) verify(spy.valid) control[data.property] = data.setValue @@ -75,24 +77,24 @@ TestCase { } function test_attached(data) { - var item1 = createTemporaryObject(mouseArea, testCase) + let item1 = createTemporaryObject(mouseArea, testCase) verify(item1) - var item2 = createTemporaryObject(mouseArea, testCase) + let item2 = createTemporaryObject(mouseArea, testCase) verify(item2) // Reset the properties to the expected default values, in case // we're not the first test that uses attached properties to be run. - var sharedTip = ToolTip.toolTip + let sharedTip = ToolTip.toolTip sharedTip[data.property] = data.defaultValue compare(item1.ToolTip[data.property], data.defaultValue) compare(item2.ToolTip[data.property], data.defaultValue) - var spy1 = signalSpy.createObject(item1, {target: item1.ToolTip, signalName: data.signalName}) + let spy1 = signalSpy.createObject(item1, {target: item1.ToolTip, signalName: data.signalName}) verify(spy1.valid) - var spy2 = signalSpy.createObject(item2, {target: item2.ToolTip, signalName: data.signalName}) + let spy2 = signalSpy.createObject(item2, {target: item2.ToolTip, signalName: data.signalName}) verify(spy2.valid) sharedSpy.signalName = data.signalName @@ -138,7 +140,7 @@ TestCase { } function test_delay(data) { - var control = createTemporaryObject(toolTip, testCase, {delay: data.delay}) + let control = createTemporaryObject(toolTip, testCase, {delay: data.delay}) compare(control.visible, false) if (data.imperative) @@ -157,7 +159,7 @@ TestCase { } function test_timeout(data) { - var control = createTemporaryObject(toolTip, testCase, {timeout: 100}) + let control = createTemporaryObject(toolTip, testCase, {timeout: 100}) compare(control.visible, false) if (data.imperative) @@ -179,7 +181,6 @@ TestCase { function test_warning() { ignoreWarning(new RegExp(".*QML QtObject: ToolTip must be attached to an Item")) - ignoreWarning(new RegExp(".*: QML ToolTip: cannot find any window to open popup in.")) object.ToolTip.show("") // don't crash (QTBUG-56243) } @@ -206,7 +207,7 @@ TestCase { } function test_makeVisibleWhileExitTransitionRunning(data) { - var control = createTemporaryObject(toolTipWithExitTransition, testCase) + let control = createTemporaryObject(toolTipWithExitTransition, testCase) // Show, hide, and show the tooltip again. Its exit transition should // start and get cancelled, and then its enter transition should run. @@ -259,18 +260,18 @@ TestCase { skip("Mouse hovering not functional on offscreen/minimal platforms") // Window shortcuts (the default context for Shortcut) require the window to have focus. - var window = testCase.Window.window + let window = testCase.Window.window verify(window) window.requestActivate() tryCompare(window, "active", true) - var root = createTemporaryObject(buttonAndShortcutComponent, testCase) + let root = createTemporaryObject(buttonAndShortcutComponent, testCase) verify(root) mouseMove(root.button, root.button.width / 2, root.button.height / 2) tryCompare(root.button.ToolTip.toolTip, "visible", true) - var shortcutActivatedSpy = signalSpy.createObject(root, { target: root.shortcut, signalName: "activated" }) + let shortcutActivatedSpy = signalSpy.createObject(root, { target: root.shortcut, signalName: "activated" }) verify(shortcutActivatedSpy.valid) keyPress(Qt.Key_A) compare(shortcutActivatedSpy.count, 1) @@ -295,13 +296,13 @@ TestCase { // QTBUG-63644 function test_hover() { - var root = createTemporaryObject(hoverComponent, testCase) + let root = createTemporaryObject(hoverComponent, testCase) verify(root) - var tooltip = root.tooltip + let tooltip = root.tooltip verify(tooltip) - for (var pos = 0; pos <= 25; pos += 5) { + for (let pos = 0; pos <= 25; pos += 5) { mouseMove(root, pos, pos) verify(tooltip.visible) } @@ -313,7 +314,7 @@ TestCase { } function test_nonAttachedToolTipShowAndHide() { - var tip = createTemporaryObject(nonAttachedToolTipComponent, testCase) + let tip = createTemporaryObject(nonAttachedToolTipComponent, testCase) verify(tip) tip.show("hello"); verify(tip.visible) @@ -346,11 +347,11 @@ TestCase { // QTBUG-74226 function test_attachedTimeout() { - var row = createTemporaryObject(timeoutButtonRowComponent, testCase) + let row = createTemporaryObject(timeoutButtonRowComponent, testCase) verify(row) // Press the button that has no timeout; it should stay visible. - var button2 = row.children[1] + let button2 = row.children[1] mousePress(button2) compare(button2.down, true) tryCompare(button2.ToolTip.toolTip, "opened", true) @@ -365,7 +366,7 @@ TestCase { tryCompare(button2.ToolTip, "visible", false) // Now, press the first button that does have a timeout; it should close on its own eventually. - var button1 = row.children[0] + let button1 = row.children[0] mousePress(button1) compare(button1.down, true) // We use a short timeout to speed up the test, but tryCompare(...opened, true) then @@ -402,7 +403,7 @@ TestCase { // QTBUG-62350 function test_wrap() { - var item = createTemporaryObject(wrapComponent, testCase) + let item = createTemporaryObject(wrapComponent, testCase) verify(item) // Avoid "cannot find window to popup in" warning that can occur if it's made visible too early. @@ -466,4 +467,20 @@ TestCase { mouseRelease(longTextButton) tryCompare(longTextButton.ToolTip.toolTip, "visible", false) } + + Component { + id: initiallyVisibleComponent + + Item { + ToolTip.text: "Some text" + ToolTip.visible: true + } + } + + // QTBUG-75483 + function test_initiallyVisible() { + let item = createTemporaryObject(initiallyVisibleComponent, testCase) + verify(item) + verify(item.ToolTip.visible) + } } diff --git a/tests/auto/quickcontrols/controls/data/tst_tumbler.qml b/tests/auto/quickcontrols/controls/data/tst_tumbler.qml index bb098f92db..3033dc756a 100644 --- a/tests/auto/quickcontrols/controls/data/tst_tumbler.qml +++ b/tests/auto/quickcontrols/controls/data/tst_tumbler.qml @@ -1,5 +1,5 @@ // Copyright (C) 2019 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only import QtQuick import QtTest @@ -60,8 +60,8 @@ TestCase { // visualItemIndex is from 0 to the amount of visible items. function itemCenterPos(visualItemIndex) { - var halfDelegateHeight = tumblerDelegateHeight / 2; - var yCenter = tumbler.y + tumbler.topPadding + halfDelegateHeight + let halfDelegateHeight = tumblerDelegateHeight / 2; + let yCenter = tumbler.y + tumbler.topPadding + halfDelegateHeight + (tumblerDelegateHeight * visualItemIndex); return Qt.point(tumblerXCenter(), yCenter); } @@ -71,22 +71,22 @@ TestCase { } function checkItemSizes() { - var contentChildren = tumbler.wrap ? tumblerView.children : tumblerView.contentItem.children; + let contentChildren = tumbler.wrap ? tumblerView.children : tumblerView.contentItem.children; verify(contentChildren.length >= tumbler.count); - for (var i = 0; i < contentChildren.length; ++i) { + for (let i = 0; i < contentChildren.length; ++i) { compare(contentChildren[i].width, tumbler.availableWidth); compare(contentChildren[i].height, tumblerDelegateHeight); } } function findView(parent) { - for (var i = 0; i < parent.children.length; ++i) { - var child = parent.children[i]; + for (let i = 0; i < parent.children.length; ++i) { + let child = parent.children[i]; if (child.hasOwnProperty("currentIndex")) { return child; } - var grandChild = findView(child); + let grandChild = findView(child); if (grandChild) return grandChild; } @@ -95,13 +95,13 @@ TestCase { } function findDelegateWithText(parent, text) { - for (var i = 0; i < parent.children.length; ++i) { - var child = parent.children[i]; + for (let i = 0; i < parent.children.length; ++i) { + let child = parent.children[i]; if (child.hasOwnProperty("text") && child.text === text) { return child; } - var grandChild = findDelegateWithText(child, text); + let grandChild = findDelegateWithText(child, text); if (grandChild) return grandChild; } @@ -113,9 +113,11 @@ TestCase { text: modelData } - function test_defaults() { + function init() { failOnWarning(/.?/) + } + function test_defaults() { let control = createTemporaryObject(defaultTumbler, testCase) verify(control) } @@ -144,7 +146,7 @@ TestCase { waitForRendering(tumbler); // Set it through user interaction. - var pos = Qt.point(tumblerXCenter(), tumbler.height / 2); + let pos = Qt.point(tumblerXCenter(), tumbler.height / 2); mouseDrag(tumbler, pos.x, pos.y, 0, tumbler.height / 3, Qt.LeftButton, Qt.NoModifier, 200); tryCompare(tumblerView, "offset", 1); compare(tumbler.currentIndex, 4); @@ -283,7 +285,7 @@ TestCase { tumblerView.highlightMoveDuration = 0; // Navigate upwards through entire wheel. - for (var j = 0; j < tumbler.count - 1; ++j) { + for (let j = 0; j < tumbler.count - 1; ++j) { keyClick(Qt.Key_Up, Qt.NoModifier); tryCompare(tumblerView, "offset", j + 1); compare(tumbler.currentIndex, tumbler.count - 1 - j); @@ -294,7 +296,7 @@ TestCase { compare(tumbler.currentIndex, 0); // Navigate downwards through entire wheel. - for (j = 0; j < tumbler.count - 1; ++j) { + for (let j = 0; j < tumbler.count - 1; ++j) { keyClick(Qt.Key_Down, Qt.NoModifier); tryCompare(tumblerView, "offset", tumbler.count - 1 - j); compare(tumbler.currentIndex, j + 1); @@ -314,9 +316,9 @@ TestCase { checkItemSizes(); wait(tumblerView.highlightMoveDuration); - var firstItemCenterPos = itemCenterPos(1); - var firstItem = tumblerView.itemAt(firstItemCenterPos.x, firstItemCenterPos.y); - var actualPos = testCase.mapFromItem(firstItem, 0, 0); + let firstItemCenterPos = itemCenterPos(1); + let firstItem = tumblerView.itemAt(firstItemCenterPos.x, firstItemCenterPos.y); + let actualPos = testCase.mapFromItem(firstItem, 0, 0); compare(actualPos.x, tumbler.leftPadding); compare(actualPos.y, tumbler.topPadding + 40); @@ -332,13 +334,13 @@ TestCase { fuzzyCompare(actualPos.x, tumbler.leftPadding, 0.0001); fuzzyCompare(actualPos.y, tumbler.topPadding, 0.0001); - var secondItemCenterPos = itemCenterPos(1); - var secondItem = tumblerView.itemAt(secondItemCenterPos.x, secondItemCenterPos.y); + let secondItemCenterPos = itemCenterPos(1); + let secondItem = tumblerView.itemAt(secondItemCenterPos.x, secondItemCenterPos.y); verify(secondItem); verify(firstItem.y < secondItem.y); - var thirdItemCenterPos = itemCenterPos(2); - var thirdItem = tumblerView.itemAt(thirdItemCenterPos.x, thirdItemCenterPos.y); + let thirdItemCenterPos = itemCenterPos(2); + let thirdItem = tumblerView.itemAt(thirdItemCenterPos.x, thirdItemCenterPos.y); verify(thirdItem); verify(firstItem.y < thirdItem.y); verify(secondItem.y < thirdItem.y); @@ -348,7 +350,7 @@ TestCase { tumbler = createTemporaryObject(tumblerComponent, testCase); verify(tumbler); - var mouseArea = createTemporaryQmlObject( + let mouseArea = createTemporaryQmlObject( "import QtQuick; TextInput { activeFocusOnTab: true; width: 50; height: 50 }", testCase, ""); tumbler.forceActiveFocus(); @@ -360,7 +362,7 @@ TestCase { } function test_datePicker() { - var component = Qt.createComponent("TumblerDatePicker.qml"); + let component = Qt.createComponent("TumblerDatePicker.qml"); compare(component.status, Component.Ready, component.errorString()); tumbler = createTemporaryObject(component, testCase); // Should not be any warnings. @@ -422,7 +424,7 @@ TestCase { } function test_listViewTimePicker() { - var root = createTemporaryObject(timePickerComponent, testCase); + let root = createTemporaryObject(timePickerComponent, testCase); verify(root); mouseDrag(root.minuteTumbler, root.minuteTumbler.width / 2, root.minuteTumbler.height / 2, 0, 50); @@ -431,7 +433,7 @@ TestCase { } function test_displacement_data() { - var data = [ + let data = [ // At 0 offset, the first item is current. { count: 6, index: 0, offset: 0, expectedDisplacement: 0 }, { count: 6, index: 1, offset: 0, expectedDisplacement: -1 }, @@ -462,9 +464,12 @@ TestCase { // count == 1 { count: 1, index: 0, offset: 0, expectedDisplacement: 0 } ]; - for (var i = 0; i < data.length; ++i) { - var row = data[i]; - row.tag = "delegate" + row.index + " offset=" + row.offset + " expectedDisplacement=" + row.expectedDisplacement; + for (let i = 0; i < data.length; ++i) { + let row = data[i]; + row.tag = "count=" + row.count + + " delegate" + row.index + + " offset=" + row.offset + + " expectedDisplacement=" + row.expectedDisplacement; } return data; } @@ -495,7 +500,7 @@ TestCase { tumbler.model = data.count; compare(tumbler.count, data.count); - var delegate = findChild(tumblerView, "delegate" + data.index); + let delegate = findChild(tumblerView, "delegate" + data.index); verify(delegate); tumblerView.offset = data.offset; @@ -552,7 +557,7 @@ TestCase { function test_explicitlyNonwrapping() { // Check that explicitly setting wrap to false works even when it was implicitly false. - var explicitlyNonWrapping = createTemporaryObject(twoItemTumbler, testCase); + let explicitlyNonWrapping = createTemporaryObject(twoItemTumbler, testCase); verify(explicitlyNonWrapping); tryCompare(explicitlyNonWrapping, "wrap", false); @@ -569,7 +574,7 @@ TestCase { function test_explicitlyWrapping() { // Check that explicitly setting wrap to true works even when it was implicitly true. - var explicitlyWrapping = createTemporaryObject(tenItemTumbler, testCase); + let explicitlyWrapping = createTemporaryObject(tenItemTumbler, testCase); verify(explicitlyWrapping); compare(explicitlyWrapping.wrap, true); @@ -641,14 +646,14 @@ TestCase { } function test_customContentItemAtConstruction(data) { - var tumbler = createTemporaryObject(data.component, testCase); + let tumbler = createTemporaryObject(data.component, testCase); // Shouldn't assert. tumbler.model = 5; compare(tumbler.count, 5); tumbler.currentIndex = 2; - var tumblerView = findView(tumbler); + let tumblerView = findView(tumbler); compare(tumblerView.currentIndex, 2); tumblerView.incrementCurrentIndex(); @@ -663,10 +668,10 @@ TestCase { } function findFirstDelegateWithText(view, text) { - var delegate = null; - var contentItem = view.hasOwnProperty("contentItem") ? view.contentItem : view; - for (var i = 0; i < contentItem.children.length && !delegate; ++i) { - var child = contentItem.children[i]; + let delegate = null; + let contentItem = view.hasOwnProperty("contentItem") ? view.contentItem : view; + for (let i = 0; i < contentItem.children.length && !delegate; ++i) { + let child = contentItem.children[i]; if (child.hasOwnProperty("text") && child.text === text) delegate = child; } @@ -689,16 +694,16 @@ TestCase { tumbler.currentIndex = 2; compare(tumblerView.currentIndex, 2); - var contentItemComponent = Qt.createComponent(data.componentPath); + let contentItemComponent = Qt.createComponent(data.componentPath); compare(contentItemComponent.status, Component.Ready); - var customContentItem = createTemporaryObject(contentItemComponent, tumbler); + let customContentItem = createTemporaryObject(contentItemComponent, tumbler); tumbler.contentItem = customContentItem; compare(tumbler.count, 5); tumblerView = findView(tumbler); compare(tumblerView.currentIndex, 2); - var delegate = findFirstDelegateWithText(tumblerView, "Custom2"); + let delegate = findFirstDelegateWithText(tumblerView, "Custom2"); verify(delegate); compare(delegate.height, defaultImplicitDelegateHeight); tryCompare(delegate.Tumbler, "displacement", 0); @@ -709,9 +714,9 @@ TestCase { } function test_displacementListView_data() { - var offset = defaultListViewTumblerOffset; + let offset = defaultListViewTumblerOffset; - var data = [ + let data = [ // At 0 contentY, the first item is current. { contentY: offset, expectedDisplacements: [ { index: 0, displacement: 0 }, @@ -738,8 +743,8 @@ TestCase { { index: 4, displacement: -0.5 } ] } ]; - for (var i = 0; i < data.length; ++i) { - var row = data[i]; + for (let i = 0; i < data.length; ++i) { + let row = data[i]; row.tag = "contentY=" + row.contentY; } return data; @@ -755,9 +760,9 @@ TestCase { // Ensure assumptions about the tumbler used in our data() function are correct. tumblerView = findView(tumbler); compare(tumblerView.contentY, -defaultImplicitDelegateHeight); - var delegateCount = 0; - var listView = tumblerView; - var listViewContentItem = tumblerView.contentItem; + let delegateCount = 0; + let listView = tumblerView; + let listViewContentItem = tumblerView.contentItem; // We use the mouse instead of setting contentY directly, otherwise the // items snap back into place. This doesn't seem to be an issue for @@ -776,25 +781,25 @@ TestCase { // to begin with, nothing changes (the displacement was always very close to 0 in the end). // Ensure that we at least cover the distance required to reach the desired contentY. - var distanceToReachContentY = data.contentY - defaultListViewTumblerOffset; - var distance = Math.abs(distanceToReachContentY) + tumbler.height / 2; + let distanceToReachContentY = data.contentY - defaultListViewTumblerOffset; + let distance = Math.abs(distanceToReachContentY) + tumbler.height / 2; // If distanceToReachContentY is 0, we're testing 0 displacement, so we don't need to do anything. if (distanceToReachContentY != 0) { mousePress(tumbler, tumblerXCenter(), tumblerYCenter()); - var dragDirection = distanceToReachContentY > 0 ? -1 : 1; - for (var i = 0; i < distance && Math.floor(listView.contentY) !== Math.floor(data.contentY); ++i) { + let dragDirection = distanceToReachContentY > 0 ? -1 : 1; + for (let i = 0; i < distance && Math.floor(listView.contentY) !== Math.floor(data.contentY); ++i) { mouseMove(tumbler, tumblerXCenter(), tumblerYCenter() + i * dragDirection); wait(1); // because Flickable pays attention to velocity, we need some time between movements (qtdeclarative ebf07c3) } } - for (var i = 0; i < data.expectedDisplacements.length; ++i) { - var delegate = findChild(listViewContentItem, "delegate" + data.expectedDisplacements[i].index); + for (let i = 0; i < data.expectedDisplacements.length; ++i) { + let delegate = findChild(listViewContentItem, "delegate" + data.expectedDisplacements[i].index); verify(delegate); compare(delegate.height, defaultImplicitDelegateHeight); // Due to the way we must perform this test, we can't expect high precision. - var expectedDisplacement = data.expectedDisplacements[i].displacement; + let expectedDisplacement = data.expectedDisplacements[i].displacement; fuzzyCompare(delegate.displacement, expectedDisplacement, 0.1, "Delegate of ListView-based Tumbler at index " + data.expectedDisplacements[i].index + " has displacement of " + delegate.displacement + " when it should be " + expectedDisplacement); @@ -807,10 +812,10 @@ TestCase { function test_listViewFlickAboveBounds_data() { // Tests that flicking above the bounds when already at the top of the // tumbler doesn't result in an incorrect displacement. - var data = []; + let data = []; // Less than two items doesn't make sense. The default visibleItemCount // is 3, so we test a bit more than double that. - for (var i = 2; i <= 7; ++i) { + for (let i = 2; i <= 7; ++i) { data.push({ tag: i + " items", model: i }); } return data; @@ -827,21 +832,21 @@ TestCase { mousePress(tumbler, tumblerXCenter(), tumblerYCenter()); // Ensure it's stationary. - var listView = tumblerView; + let listView = tumblerView; compare(listView.contentY, defaultListViewTumblerOffset); // We could just move up until the contentY changed, but this is safer. - var distance = tumbler.height; - var changed = false; + let distance = tumbler.height; + let changed = false; - for (var i = 0; i < distance && !changed; ++i) { + for (let i = 0; i < distance && !changed; ++i) { mouseMove(tumbler, tumblerXCenter(), tumblerYCenter() + i, 10); // Don't test until the contentY has actually changed. if (Math.abs(listView.contentY) - listView.preferredHighlightBegin > 0.01) { - for (var delegateIndex = 0; delegateIndex < Math.min(tumbler.count, tumbler.visibleItemCount); ++delegateIndex) { - var delegate = findChild(listView.contentItem, "delegate" + delegateIndex); + for (let delegateIndex = 0; delegateIndex < Math.min(tumbler.count, tumbler.visibleItemCount); ++delegateIndex) { + let delegate = findChild(listView.contentItem, "delegate" + delegateIndex); verify(delegate); verify(delegate.displacement <= -delegateIndex, "Delegate at index " + delegateIndex + " has a displacement of " @@ -868,7 +873,7 @@ TestCase { } function test_visibleItemCount_data() { - var data = [ + let data = [ // e.g. {0: 2} = {delegate index: y pos / delegate height} // Skip item at index 3, because it's out of view. { model: 6, visibleItemCount: 5, expectedYPositions: {0: 2, 1: 3, 2: 4, 4: 0} }, @@ -877,7 +882,7 @@ TestCase { { model: 2, visibleItemCount: 1, expectedYPositions: {0: 0} }, ]; - for (var i = 0; i < data.length; ++i) { + for (let i = 0; i < data.length; ++i) { data[i].tag = "items=" + data[i].model + ", visibleItemCount=" + data[i].visibleItemCount; } return data; @@ -892,11 +897,11 @@ TestCase { tumbler.model = data.model; compare(tumbler.count, data.model); - for (var delegateIndex = 0; delegateIndex < data.visibleItemCount; ++delegateIndex) { + for (let delegateIndex = 0; delegateIndex < data.visibleItemCount; ++delegateIndex) { if (data.expectedYPositions.hasOwnProperty(delegateIndex)) { - var delegate = findChild(tumblerView, "delegate" + delegateIndex); + let delegate = findChild(tumblerView, "delegate" + delegateIndex); verify(delegate, "Delegate found at index " + delegateIndex); - var expectedYPos = data.expectedYPositions[delegateIndex] * tumblerDelegateHeight; + let expectedYPos = data.expectedYPositions[delegateIndex] * tumblerDelegateHeight; compare(delegate.mapToItem(tumbler.contentItem, 0, 0).y, expectedYPos); } } @@ -925,7 +930,7 @@ TestCase { createTemporaryObject(noParentDelegateComponent, null); ignoreWarning(/.*Tumbler: attempting to access attached property on item without an \"index\" property/); - var object = createTemporaryObject(noParentDelegateComponent, testCase); + let object = createTemporaryObject(noParentDelegateComponent, testCase); verify(object); } @@ -944,15 +949,15 @@ TestCase { } function test_padding_data() { - var data = []; + let data = []; data.push({ padding: 0 }); data.push({ padding: 10 }); data.push({ left: 10, top: 10 }); data.push({ right: 10, bottom: 10 }); - for (var i = 0; i < data.length; ++i) { - var tag = ""; + for (let i = 0; i < data.length; ++i) { + let tag = ""; if (data[i].padding !== undefined) tag += "padding: " + data[i].padding + " "; @@ -1001,24 +1006,24 @@ TestCase { compare(tumbler.contentItem.x, tumbler.leftPadding); compare(tumbler.contentItem.y, tumbler.topPadding); - var pathView = tumbler.contentItem; - var expectedDelegateHeight = tumbler.availableHeight / tumbler.visibleItemCount; - var itemIndicesInVisualOrder = [4, 0, 1]; - for (var i = 0; i < itemIndicesInVisualOrder.length; ++i) { - var delegate = findChild(pathView, "delegate" + itemIndicesInVisualOrder[i]); + let pathView = tumbler.contentItem; + let expectedDelegateHeight = tumbler.availableHeight / tumbler.visibleItemCount; + let itemIndicesInVisualOrder = [4, 0, 1]; + for (let i = 0; i < itemIndicesInVisualOrder.length; ++i) { + let delegate = findChild(pathView, "delegate" + itemIndicesInVisualOrder[i]); verify(delegate, "Couldn't find delegate at index " + itemIndicesInVisualOrder[i] + " (iteration " + i + " out of " + (pathView.children.length - 1) + ")"); compare(delegate.width, tumbler.availableWidth); compare(delegate.height, expectedDelegateHeight); - var expectedY = tumbler.topPadding + i * expectedDelegateHeight; - var mappedPos = delegate.mapToItem(null, delegate.width / 2, 0); + let expectedY = tumbler.topPadding + i * expectedDelegateHeight; + let mappedPos = delegate.mapToItem(null, delegate.width / 2, 0); fuzzyCompare(mappedPos.y, expectedY, 0.5, "Tumbler's PathView delegate at index " + itemIndicesInVisualOrder[i] + " should have a y pos of " + expectedY + ", but it's actually " + mappedPos.y.toFixed(20)); - var expectedX = tumbler.leftPadding; + let expectedX = tumbler.leftPadding; compare(delegate.mapToItem(null, 0, 0).x, expectedX, "Tumbler's PathView delegate at index " + itemIndicesInVisualOrder[i] + " should have a x pos of " + expectedX + ", but it's actually " + mappedPos.x.toFixed(20)); @@ -1047,7 +1052,7 @@ TestCase { 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) + for (let y = tumbler.height / 2; y >= tumbler.height / 4; y -= 10) mouseMove(tumbler, tumbler.width / 2, y, 1) compare(tumbler.moving, true) @@ -1081,15 +1086,15 @@ TestCase { } function test_qtbug61374() { - var row = createTemporaryObject(qtbug61374Component, testCase); + let row = createTemporaryObject(qtbug61374Component, testCase); verify(row); - var tumbler = row.tumbler; + let tumbler = row.tumbler; tryCompare(tumbler, "currentIndex", 2); tumblerView = findView(tumbler); - var label = row.label; + let label = row.label; compare(label.text, "2"); } @@ -1121,16 +1126,16 @@ TestCase { tryCompare(tumbler, "moving", false) compare(tumbler.visibleItemCount, 5) - for (var i = 0; i < 5; ++i) { + for (let i = 0; i < 5; ++i) { // Find the item through its text, as that's easier than child/itemAt(). - var text = data.expectedVisibleIndices[i].toString() - var item = findDelegateWithText(tumblerView, text) + let text = data.expectedVisibleIndices[i].toString() + let item = findDelegateWithText(tumblerView, text) verify(item, "found no item with text \"" + text + "\"") compare(item.text, data.expectedVisibleIndices[i].toString()) // Ensure that it's at the position we expect. - var expectedPos = itemTopLeftPos(i) - var actualPos = testCase.mapFromItem(item, 0, 0) + let expectedPos = itemTopLeftPos(i) + let actualPos = testCase.mapFromItem(item, 0, 0) compare(actualPos.x, expectedPos.x, "expected delegate with text " + item.text + " to have an x pos of " + expectedPos.x + " but it was " + actualPos.x) compare(actualPos.y, expectedPos.y, "expected delegate with text " + item.text @@ -1147,7 +1152,7 @@ TestCase { } function test_setCurrentIndexOnImperativeModelChange() { - var tumbler = createTemporaryObject(setCurrentIndexOnImperativeModelChangeComponent, testCase); + let tumbler = createTemporaryObject(setCurrentIndexOnImperativeModelChangeComponent, testCase); verify(tumbler); tumbler.model = 4 @@ -1184,10 +1189,10 @@ TestCase { } function test_setCurrentIndexOnDeclarativeModelChange() { - var root = createTemporaryObject(setCurrentIndexOnDeclarativeModelChangeComponent, testCase); + let root = createTemporaryObject(setCurrentIndexOnDeclarativeModelChangeComponent, testCase); verify(root); - var tumbler = root.tumbler; + let tumbler = root.tumbler; compare(tumbler.count, 4); compare(tumbler.wrap, false); tumblerView = findView(tumbler); @@ -1214,7 +1219,7 @@ TestCase { currentIndex: 15 }) - var delegate = findChild(tumblerView, "delegate15") + let delegate = findChild(tumblerView, "delegate15") verify(delegate) tryCompare(delegate, "displacement", 0) @@ -1239,9 +1244,51 @@ TestCase { } function test_initialCurrentIndex() { - var tumbler = createTemporaryObject(initialCurrentIndexTumbler, testCase, {wrap: true}); + let tumbler = createTemporaryObject(initialCurrentIndexTumbler, testCase, {wrap: true}); compare(tumbler.currentIndex, 4); tumbler = createTemporaryObject(initialCurrentIndexTumbler, testCase, {wrap: false}); compare(tumbler.currentIndex, 4); } + + // QTBUG-109995 + Component { + id: flickTumbler + Flickable { + width: 50 + height: 200 + interactive: true + contentHeight: 400 + property alias tumblerItem: noWrapTumbler + Tumbler { + id: noWrapTumbler + anchors.fill: parent + model: 20 + wrap: false + } + } + } + + function test_flick() { + let control = createTemporaryObject(flickTumbler, testCase) + verify(control) + + let tumbler = control.tumblerItem + compare(tumbler.count, 20) + compare(tumbler.wrap, false) + + let touch = touchEvent(tumbler) + let tumblerView = findView(tumbler) + let delegateHeight = tumblerView.children[0].children[0].height + + // Move delegates through touch operation and check the current index + touch.press(0, tumblerView, control.width / 2, control.height / 2).commit() + // Move slowly, otherwise its considered as flick which cause current index + // to be varied according to its velocity + let scrollOffset = control.height / 2 + for (; scrollOffset > delegateHeight / 2; scrollOffset-=5) { + touch.move(0, tumblerView, control.width / 2, scrollOffset).commit() + } + touch.release(0, tumblerView, control.width / 2, scrollOffset).commit() + tryCompare(tumblerView, "currentIndex", 2) + } } diff --git a/tests/auto/quickcontrols/controls/data/tst_weeknumbercolumn.qml b/tests/auto/quickcontrols/controls/data/tst_weeknumbercolumn.qml index 40566b018c..11868bfbbf 100644 --- a/tests/auto/quickcontrols/controls/data/tst_weeknumbercolumn.qml +++ b/tests/auto/quickcontrols/controls/data/tst_weeknumbercolumn.qml @@ -1,5 +1,5 @@ // Copyright (C) 2021 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only import QtQuick import QtQuick.Controls @@ -18,15 +18,17 @@ TestCase { WeekNumberColumn { } } - function test_defaults() { + function init() { failOnWarning(/.?/) + } + function test_defaults() { let control = createTemporaryObject(component, testCase) verify(control) } function test_locale() { - var control = component.createObject(testCase) + let control = component.createObject(testCase) compare(control.contentItem.children.length, 6 + 1) @@ -35,12 +37,12 @@ TestCase { // en_US: [48...53] control.locale = Qt.locale("en_US") - for (var i = 0; i < 6; ++i) + for (let i = 0; i < 6; ++i) compare(control.contentItem.children[i].text, (i + 48).toString()) // no_NO: [49...1] control.locale = Qt.locale("no_NO") - for (var j = 0; j < 5; ++j) + for (let j = 0; j < 5; ++j) compare(control.contentItem.children[j].text, (j + 49).toString()) compare(control.contentItem.children[5].text, "1") @@ -48,7 +50,7 @@ TestCase { } function test_range() { - var control = component.createObject(testCase) + let control = component.createObject(testCase) control.month = 0 compare(control.month, 0) @@ -82,7 +84,7 @@ TestCase { } function test_font() { - var control = component.createObject(testCase) + let control = component.createObject(testCase) verify(control.contentItem.children[0]) |