aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/quickcontrols/controls/data/tst_scrollview.qml
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/quickcontrols/controls/data/tst_scrollview.qml')
-rw-r--r--tests/auto/quickcontrols/controls/data/tst_scrollview.qml193
1 files changed, 143 insertions, 50 deletions
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)
+ }
}