aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@qt.io>2016-09-22 08:44:34 +0200
committerJ-P Nurmi <jpnurmi@qt.io>2016-09-22 08:55:29 +0200
commitab91c57135f7a86437a5a4341cd32df1d4682480 (patch)
tree713612fe2c27ff43ab4a3d5ed3b363c6141d5fbf /tests
parentc5a44092c8b73c540862c4a160c31487a8518992 (diff)
parent7193318330bc518255fb7ed008c144578f49b4bd (diff)
Merge remote-tracking branch 'origin/5.7' into 5.8
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/applicationwindow/tst_applicationwindow.cpp4
-rw-r--r--tests/auto/controls/data/tst_control.qml6
-rw-r--r--tests/auto/controls/data/tst_drawer.qml1
-rw-r--r--tests/auto/controls/data/tst_popup.qml90
-rw-r--r--tests/auto/controls/data/tst_switch.qml127
-rw-r--r--tests/auto/controls/data/tst_switchdelegate.qml216
-rw-r--r--tests/auto/drawer/BLACKLIST2
-rw-r--r--tests/auto/drawer/data/header.qml57
-rw-r--r--tests/auto/drawer/data/reposition.qml58
-rw-r--r--tests/auto/drawer/tst_drawer.cpp137
10 files changed, 683 insertions, 15 deletions
diff --git a/tests/auto/applicationwindow/tst_applicationwindow.cpp b/tests/auto/applicationwindow/tst_applicationwindow.cpp
index b712075f..fb7f96b8 100644
--- a/tests/auto/applicationwindow/tst_applicationwindow.cpp
+++ b/tests/auto/applicationwindow/tst_applicationwindow.cpp
@@ -318,7 +318,7 @@ void tst_applicationwindow::attachedProperties()
QVERIFY(!childWindowControl->property("attached_activeFocusControl").value<QQuickItem *>());
QVERIFY(!childWindowControl->property("attached_header").value<QQuickItem *>());
QVERIFY(!childWindowControl->property("attached_footer").value<QQuickItem *>());
- QVERIFY(!childWindowControl->property("attached_overlay").value<QQuickItem *>());
+ QCOMPARE(childWindowControl->property("attached_overlay").value<QQuickItem *>(), QQuickOverlay::overlay(childWindow));
QQuickItem *childWindowItem = object->property("childWindowItem").value<QQuickItem *>();
QVERIFY(childWindowItem);
@@ -327,7 +327,7 @@ void tst_applicationwindow::attachedProperties()
QVERIFY(!childWindowItem->property("attached_activeFocusControl").value<QQuickItem *>());
QVERIFY(!childWindowItem->property("attached_header").value<QQuickItem *>());
QVERIFY(!childWindowItem->property("attached_footer").value<QQuickItem *>());
- QVERIFY(!childWindowItem->property("attached_overlay").value<QQuickItem *>());
+ QCOMPARE(childWindowItem->property("attached_overlay").value<QQuickItem *>(), QQuickOverlay::overlay(childWindow));
QObject *childWindowObject = object->property("childWindowObject").value<QObject *>();
QVERIFY(childWindowObject);
diff --git a/tests/auto/controls/data/tst_control.qml b/tests/auto/controls/data/tst_control.qml
index 0061440b..dc84ff93 100644
--- a/tests/auto/controls/data/tst_control.qml
+++ b/tests/auto/controls/data/tst_control.qml
@@ -880,6 +880,12 @@ TestCase {
mouseMove(control, -10, -10)
compare(control.hovered, false)
+ mouseMove(control, control.width / 2, control.height / 2)
+ compare(control.hovered, true)
+
+ control.visible = false
+ compare(control.hovered, false)
+
control.destroy()
}
diff --git a/tests/auto/controls/data/tst_drawer.qml b/tests/auto/controls/data/tst_drawer.qml
index bfa8dd10..2e1f32dc 100644
--- a/tests/auto/controls/data/tst_drawer.qml
+++ b/tests/auto/controls/data/tst_drawer.qml
@@ -60,6 +60,7 @@ TestCase {
compare(control.edge, Qt.LeftEdge)
compare(control.position, 0.0)
compare(control.dragMargin, Qt.styleHints.startDragDistance)
+ compare(control.parent, ApplicationWindow.overlay)
control.destroy()
}
diff --git a/tests/auto/controls/data/tst_popup.qml b/tests/auto/controls/data/tst_popup.qml
index a86e800e..5609d47f 100644
--- a/tests/auto/controls/data/tst_popup.qml
+++ b/tests/auto/controls/data/tst_popup.qml
@@ -355,6 +355,48 @@ TestCase {
control.destroy()
}
+ function test_resetSize() {
+ var control = popupControl.createObject(testCase, {visible: true, margins: 0})
+ verify(control)
+
+ control.width = control.implicitWidth = testCase.width + 10
+ control.height = control.implicitHeight = testCase.height + 10
+
+ compare(control.width, testCase.width + 10)
+ compare(control.height, testCase.height + 10)
+
+ control.width = undefined
+ control.height = undefined
+ compare(control.width, testCase.width)
+ compare(control.height, testCase.height)
+
+ control.destroy()
+ }
+
+ function test_negativeMargins() {
+ var control = popupControl.createObject(testCase, {implicitWidth: testCase.width, implicitHeight: testCase.height})
+ verify(control)
+
+ control.open()
+ verify(control.visible)
+
+ compare(control.x, 0)
+ compare(control.y, 0)
+
+ compare(control.margins, -1)
+ compare(control.topMargin, -1)
+ compare(control.leftMargin, -1)
+ compare(control.rightMargin, -1)
+ compare(control.bottomMargin, -1)
+
+ control.x = -10
+ control.y = -10
+ compare(control.x, 0)
+ compare(control.y, 0)
+
+ control.destroy()
+ }
+
function test_margins() {
var control = popupControl.createObject(testCase, {width: 100, height: 100})
verify(control)
@@ -975,14 +1017,52 @@ TestCase {
var control = popupControl.createObject(testCase)
verify(control)
- control.width = 200
- control.height = 200
-
control.open()
waitForRendering(control.contentItem)
- compare(control.width, 200)
- compare(control.height, 200)
+ // implicit size of the content
+ control.contentItem.implicitWidth = 10
+ compare(control.implicitWidth, 10 + control.leftPadding + control.rightPadding)
+ compare(control.width, control.implicitWidth)
+ compare(control.contentItem.width, control.width - control.leftPadding - control.rightPadding)
+
+ control.contentItem.implicitHeight = 20
+ compare(control.implicitHeight, 20 + control.topPadding + control.bottomPadding)
+ compare(control.height, control.implicitHeight)
+ compare(control.contentItem.height, control.height - control.topPadding - control.bottomPadding)
+
+ // implicit size of the popup
+ control.implicitWidth = 30
+ compare(control.implicitWidth, 30)
+ compare(control.width, 30)
+ compare(control.contentItem.width, control.width - control.leftPadding - control.rightPadding)
+
+ control.implicitHeight = 40
+ compare(control.implicitHeight, 40)
+ compare(control.height, 40)
+ compare(control.contentItem.height, control.height - control.topPadding - control.bottomPadding)
+
+ // set explicit size
+ control.width = 50
+ compare(control.implicitWidth, 30)
+ compare(control.width, 50)
+ compare(control.contentItem.width, control.width - control.leftPadding - control.rightPadding)
+
+ control.height = 60
+ compare(control.implicitHeight, 40)
+ compare(control.height, 60)
+ compare(control.contentItem.height, control.height - control.topPadding - control.bottomPadding)
+
+ // reset explicit size
+ control.width = undefined
+ compare(control.implicitWidth, 30)
+ compare(control.width, 30)
+ compare(control.contentItem.width, control.width - control.leftPadding - control.rightPadding)
+
+ control.height = undefined
+ compare(control.implicitHeight, 40)
+ compare(control.height, 40)
+ compare(control.contentItem.height, control.height - control.topPadding - control.bottomPadding)
control.destroy()
}
diff --git a/tests/auto/controls/data/tst_switch.qml b/tests/auto/controls/data/tst_switch.qml
index 6c145fc1..f3843cf7 100644
--- a/tests/auto/controls/data/tst_switch.qml
+++ b/tests/auto/controls/data/tst_switch.qml
@@ -95,6 +95,29 @@ TestCase {
control.destroy()
}
+ function test_pressed_data() {
+ return [
+ { tag: "indicator", x: 15 },
+ { tag: "background", x: 5 }
+ ]
+ }
+
+ function test_pressed(data) {
+ var control = swtch.createObject(testCase, {padding: 10})
+ verify(control)
+
+ // stays pressed when dragged outside
+ compare(control.pressed, false)
+ mousePress(control, data.x, control.height / 2, Qt.LeftButton)
+ compare(control.pressed, true)
+ mouseMove(control, -1, control.height / 2)
+ compare(control.pressed, true)
+ mouseRelease(control, -1, control.height / 2, Qt.LeftButton)
+ compare(control.pressed, false)
+
+ control.destroy()
+ }
+
function test_mouse() {
var control = swtch.createObject(testCase)
verify(control)
@@ -177,6 +200,110 @@ TestCase {
control.destroy()
}
+ function test_drag() {
+ var control = swtch.createObject(testCase, {leftPadding: 100, rightPadding: 100})
+ verify(control)
+
+ var spy = signalSequenceSpy.createObject(control, {target: control})
+ compare(control.position, 0.0)
+ compare(control.checked, false)
+ compare(control.pressed, false)
+
+ // press-drag-release inside the indicator
+ spy.expectedSequence = [["pressedChanged", { "pressed": true, "checked": false }],
+ "pressed"]
+ mousePress(control.indicator, 0)
+ compare(control.position, 0.0)
+ compare(control.checked, false)
+ compare(control.pressed, true)
+ verify(spy.success)
+
+ mouseMove(control.indicator, control.width)
+ compare(control.position, 1.0)
+ compare(control.checked, false)
+ compare(control.pressed, true)
+
+ spy.expectedSequence = [["pressedChanged", { "pressed": false, "checked": false }],
+ ["checkedChanged", { "pressed": false, "checked": true }],
+ "released",
+ "clicked"]
+ mouseRelease(control.indicator, control.indicator.width)
+ compare(control.position, 1.0)
+ compare(control.checked, true)
+ compare(control.pressed, false)
+ verify(spy.success)
+
+ // press-drag-release outside the indicator
+ spy.expectedSequence = [["pressedChanged", { "pressed": true, "checked": true }],
+ "pressed"]
+ mousePress(control, 0)
+ compare(control.position, 1.0)
+ compare(control.checked, true)
+ compare(control.pressed, true)
+ verify(spy.success)
+
+ mouseMove(control, control.width - control.rightPadding)
+ compare(control.position, 1.0)
+ compare(control.checked, true)
+ compare(control.pressed, true)
+
+ mouseMove(control, control.width / 2)
+ compare(control.position, 0.5)
+ compare(control.checked, true)
+ compare(control.pressed, true)
+
+ mouseMove(control, control.leftPadding)
+ compare(control.position, 0.0)
+ compare(control.checked, true)
+ compare(control.pressed, true)
+
+ spy.expectedSequence = [["pressedChanged", { "pressed": false, "checked": true }],
+ ["checkedChanged", { "pressed": false, "checked": false }],
+ "released",
+ "clicked"]
+ mouseRelease(control, control.width)
+ compare(control.position, 0.0)
+ compare(control.checked, false)
+ compare(control.pressed, false)
+ verify(spy.success)
+
+ // press-drag-release from and to outside the indicator
+ spy.expectedSequence = [["pressedChanged", { "pressed": true, "checked": false }],
+ "pressed"]
+ mousePress(control, control.width)
+ compare(control.position, 0.0)
+ compare(control.checked, false)
+ compare(control.pressed, true)
+ verify(spy.success)
+
+ mouseMove(control, control.width - control.rightPadding)
+ compare(control.position, 0.0)
+ compare(control.checked, false)
+ compare(control.pressed, true)
+
+ mouseMove(control, control.width / 2)
+ compare(control.position, 0.5)
+ compare(control.checked, false)
+ compare(control.pressed, true)
+
+ mouseMove(control, control.width - control.rightPadding)
+ compare(control.position, 1.0)
+ compare(control.checked, false)
+ compare(control.pressed, true)
+
+ spy.expectedSequence = [["pressedChanged", { "pressed": false, "checked": false }],
+ ["checkedChanged", { "pressed": false, "checked": true }],
+ "released",
+ "clicked"]
+ mouseRelease(control, control.width)
+ compare(control.position, 1.0)
+ compare(control.checked, true)
+ compare(control.pressed, false)
+ verify(spy.success)
+
+ control.destroy()
+ }
+
function test_keys() {
var control = swtch.createObject(testCase)
verify(control)
diff --git a/tests/auto/controls/data/tst_switchdelegate.qml b/tests/auto/controls/data/tst_switchdelegate.qml
index 2d5c6089..4a5d711f 100644
--- a/tests/auto/controls/data/tst_switchdelegate.qml
+++ b/tests/auto/controls/data/tst_switchdelegate.qml
@@ -55,6 +55,13 @@ TestCase {
SwitchDelegate {}
}
+ Component {
+ id: signalSequenceSpy
+ SignalSequenceSpy {
+ signals: ["pressed", "released", "canceled", "clicked", "pressedChanged", "checkedChanged"]
+ }
+ }
+
// TODO: data-fy tst_checkbox (rename to tst_check?) so we don't duplicate its tests here?
function test_defaults() {
@@ -83,4 +90,213 @@ TestCase {
compare(control.baselineOffset, control.contentItem.y + control.contentItem.baselineOffset);
control.destroy();
}
+
+ function test_pressed_data() {
+ return [
+ { tag: "indicator", x: 15 },
+ { tag: "background", x: 5 }
+ ]
+ }
+
+ function test_pressed(data) {
+ var control = switchDelegate.createObject(testCase, {padding: 10})
+ verify(control)
+
+ // stays pressed when dragged outside
+ compare(control.pressed, false)
+ mousePress(control, data.x, control.height / 2, Qt.LeftButton)
+ compare(control.pressed, true)
+ mouseMove(control, -1, control.height / 2)
+ compare(control.pressed, true)
+ mouseRelease(control, -1, control.height / 2, Qt.LeftButton)
+ compare(control.pressed, false)
+
+ control.destroy()
+ }
+
+ function test_mouse() {
+ var control = switchDelegate.createObject(testCase)
+ verify(control)
+
+ // check
+ var spy = signalSequenceSpy.createObject(control, {target: control})
+ spy.expectedSequence = [["pressedChanged", { "pressed": true, "checked": false }],
+ "pressed"]
+ mousePress(control, control.width / 2, control.height / 2, Qt.LeftButton)
+ compare(control.pressed, true)
+ verify(spy.success)
+ spy.expectedSequence = [["pressedChanged", { "pressed": false, "checked": false }],
+ ["checkedChanged", { "pressed": false, "checked": true }],
+ "released",
+ "clicked"]
+ mouseRelease(control, control.width / 2, control.height / 2, Qt.LeftButton)
+ compare(control.checked, true)
+ compare(control.pressed, false)
+ verify(spy.success)
+
+ // uncheck
+ spy.expectedSequence = [["pressedChanged", { "pressed": true, "checked": true }],
+ "pressed"]
+ mousePress(control, control.width / 2, control.height / 2, Qt.LeftButton)
+ compare(control.pressed, true)
+ verify(spy.success)
+ spy.expectedSequence = [["pressedChanged", { "pressed": false, "checked": true }],
+ ["checkedChanged", { "pressed": false, "checked": false }],
+ "released",
+ "clicked"]
+ mouseRelease(control, control.width / 2, control.height / 2, Qt.LeftButton)
+ compare(control.checked, false)
+ compare(control.pressed, false)
+ verify(spy.success)
+
+ // release on the right
+ spy.expectedSequence = [["pressedChanged", { "pressed": true, "checked": false }],
+ "pressed"]
+ mousePress(control, control.width / 2, control.height / 2, Qt.LeftButton)
+ compare(control.pressed, true)
+ verify(spy.success)
+ mouseMove(control, control.width * 2, control.height / 2, 0, Qt.LeftButton)
+ compare(control.pressed, true)
+ spy.expectedSequence = [["pressedChanged", { "pressed": false, "checked": false }],
+ ["checkedChanged", { "pressed": false, "checked": true }],
+ "released",
+ "clicked"]
+ mouseRelease(control, control.width * 2, control.height / 2, Qt.LeftButton)
+ compare(control.checked, true)
+ compare(control.pressed, false)
+ verify(spy.success)
+
+ // release on the left
+ spy.expectedSequence = [["pressedChanged", { "pressed": true, "checked": true }],
+ "pressed"]
+ mousePress(control, control.width / 2, control.height / 2, Qt.LeftButton)
+ compare(control.pressed, true)
+ verify(spy.success)
+ mouseMove(control, -control.width, control.height / 2, 0, Qt.LeftButton)
+ compare(control.pressed, true)
+ spy.expectedSequence = [["pressedChanged", { "pressed": false, "checked": true }],
+ ["checkedChanged", { "pressed": false, "checked": false }],
+ "released",
+ "clicked"]
+ mouseRelease(control, -control.width, control.height / 2, Qt.LeftButton)
+ compare(control.checked, false)
+ compare(control.pressed, false)
+ verify(spy.success)
+
+ // right button
+ spy.expectedSequence = []
+ mousePress(control, control.width / 2, control.height / 2, Qt.RightButton)
+ compare(control.pressed, false)
+ verify(spy.success)
+ mouseRelease(control, control.width / 2, control.height / 2, Qt.RightButton)
+ compare(control.checked, false)
+ compare(control.pressed, false)
+ verify(spy.success)
+
+ control.destroy()
+ }
+
+ function test_drag() {
+ var control = switchDelegate.createObject(testCase, {leftPadding: 100, rightPadding: 100})
+ verify(control)
+
+ var spy = signalSequenceSpy.createObject(control, {target: control})
+ compare(control.position, 0.0)
+ compare(control.checked, false)
+ compare(control.pressed, false)
+
+ // press-drag-release inside the indicator
+ spy.expectedSequence = [["pressedChanged", { "pressed": true, "checked": false }],
+ "pressed"]
+ mousePress(control.indicator, 0)
+ compare(control.position, 0.0)
+ compare(control.checked, false)
+ compare(control.pressed, true)
+ verify(spy.success)
+
+ mouseMove(control.indicator, control.width)
+ compare(control.position, 1.0)
+ compare(control.checked, false)
+ compare(control.pressed, true)
+
+ spy.expectedSequence = [["pressedChanged", { "pressed": false, "checked": false }],
+ ["checkedChanged", { "pressed": false, "checked": true }],
+ "released",
+ "clicked"]
+ mouseRelease(control.indicator, control.indicator.width)
+ compare(control.position, 1.0)
+ compare(control.checked, true)
+ compare(control.pressed, false)
+ verify(spy.success)
+
+ // press-drag-release outside the indicator
+ spy.expectedSequence = [["pressedChanged", { "pressed": true, "checked": true }],
+ "pressed"]
+ mousePress(control, 0)
+ compare(control.position, 1.0)
+ compare(control.checked, true)
+ compare(control.pressed, true)
+ verify(spy.success)
+
+ mouseMove(control, control.width - control.rightPadding)
+ compare(control.position, 1.0)
+ compare(control.checked, true)
+ compare(control.pressed, true)
+
+ mouseMove(control, control.width / 2)
+ compare(control.position, 0.5)
+ compare(control.checked, true)
+ compare(control.pressed, true)
+
+ mouseMove(control, control.leftPadding)
+ compare(control.position, 0.0)
+ compare(control.checked, true)
+ compare(control.pressed, true)
+
+ spy.expectedSequence = [["pressedChanged", { "pressed": false, "checked": true }],
+ ["checkedChanged", { "pressed": false, "checked": false }],
+ "released",
+ "clicked"]
+ mouseRelease(control, control.width)
+ compare(control.position, 0.0)
+ compare(control.checked, false)
+ compare(control.pressed, false)
+ verify(spy.success)
+
+ // press-drag-release from and to outside the indicator
+ spy.expectedSequence = [["pressedChanged", { "pressed": true, "checked": false }],
+ "pressed"]
+ mousePress(control, control.width)
+ compare(control.position, 0.0)
+ compare(control.checked, false)
+ compare(control.pressed, true)
+ verify(spy.success)
+
+ mouseMove(control, control.width - control.rightPadding)
+ compare(control.position, 0.0)
+ compare(control.checked, false)
+ compare(control.pressed, true)
+
+ mouseMove(control, control.width / 2)
+ compare(control.position, 0.5)
+ compare(control.checked, false)
+ compare(control.pressed, true)
+
+ mouseMove(control, control.width - control.rightPadding)
+ compare(control.position, 1.0)
+ compare(control.checked, false)
+ compare(control.pressed, true)
+
+ spy.expectedSequence = [["pressedChanged", { "pressed": false, "checked": false }],
+ ["checkedChanged", { "pressed": false, "checked": true }],
+ "released",
+ "clicked"]
+ mouseRelease(control, control.width)
+ compare(control.position, 1.0)
+ compare(control.checked, true)
+ compare(control.pressed, false)
+ verify(spy.success)
+
+ control.destroy()
+ }
}
diff --git a/tests/auto/drawer/BLACKLIST b/tests/auto/drawer/BLACKLIST
new file mode 100644
index 00000000..1b06b49c
--- /dev/null
+++ b/tests/auto/drawer/BLACKLIST
@@ -0,0 +1,2 @@
+[touch]
+windows
diff --git a/tests/auto/drawer/data/header.qml b/tests/auto/drawer/data/header.qml
new file mode 100644
index 00000000..9a352ffc
--- /dev/null
+++ b/tests/auto/drawer/data/header.qml
@@ -0,0 +1,57 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of The Qt Company Ltd nor the names of its
+** contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQuick 2.6
+import QtQuick.Controls 2.0
+
+ApplicationWindow {
+ width: 400
+ height: 400
+
+ property alias drawer: drawer
+
+ header: ToolBar { }
+
+ Drawer {
+ id: drawer
+ width: 200
+ height: parent.height
+ }
+}
diff --git a/tests/auto/drawer/data/reposition.qml b/tests/auto/drawer/data/reposition.qml
new file mode 100644
index 00000000..abaec5ae
--- /dev/null
+++ b/tests/auto/drawer/data/reposition.qml
@@ -0,0 +1,58 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of The Qt Company Ltd nor the names of its
+** contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQuick 2.6
+import QtQuick.Controls 2.0
+
+ApplicationWindow {
+ width: 400
+ height: 400
+
+ property alias drawer: drawer
+
+ header: Item { implicitHeight: 50 }
+ footer: Item { implicitHeight: 50 }
+
+ Drawer {
+ id: drawer
+ width: parent.width / 2
+ implicitHeight: parent.height
+ }
+}
diff --git a/tests/auto/drawer/tst_drawer.cpp b/tests/auto/drawer/tst_drawer.cpp
index 8b02e95c..1ded5bf4 100644
--- a/tests/auto/drawer/tst_drawer.cpp
+++ b/tests/auto/drawer/tst_drawer.cpp
@@ -40,9 +40,13 @@
#include "../shared/visualtestutil.h"
#include <QtGui/qstylehints.h>
+#include <QtGui/qtouchdevice.h>
#include <QtGui/qguiapplication.h>
+#include <QtGui/qpa/qwindowsysteminterface.h>
+#include <QtQuick/private/qquickwindow_p.h>
#include <QtQuickTemplates2/private/qquickapplicationwindow_p.h>
#include <QtQuickTemplates2/private/qquickoverlay_p.h>
+#include <QtQuickTemplates2/private/qquickpopup_p_p.h>
#include <QtQuickTemplates2/private/qquickdrawer_p.h>
#include <QtQuickTemplates2/private/qquickbutton_p.h>
#include <QtQuickTemplates2/private/qquickslider_p.h>
@@ -66,6 +70,7 @@ private slots:
void dragMargin();
void reposition();
+ void header();
void hover_data();
void hover();
@@ -74,6 +79,9 @@ private slots:
void wheel();
void multiple();
+
+ void touch_data();
+ void touch();
};
void tst_Drawer::visible_data()
@@ -323,27 +331,88 @@ void tst_Drawer::dragMargin()
QTest::mouseRelease(window, Qt::LeftButton, Qt::NoModifier, QPoint(window->width() - rightDistance, drawer->height() / 2));
}
+static QRectF geometry(const QQuickItem *item)
+{
+ return QRectF(item->x(), item->y(), item->width(), item->height());
+}
+
void tst_Drawer::reposition()
{
- QQuickApplicationHelper helper(this, QStringLiteral("applicationwindow.qml"));
+ QQuickApplicationHelper helper(this, QStringLiteral("reposition.qml"));
QQuickApplicationWindow *window = helper.appWindow;
window->show();
- window->requestActivate();
- QVERIFY(QTest::qWaitForWindowActive(window));
+ QVERIFY(QTest::qWaitForWindowExposed(window));
- QQuickDrawer *drawer = helper.appWindow->property("drawer").value<QQuickDrawer*>();
+ QQuickDrawer *drawer = window->property("drawer").value<QQuickDrawer*>();
QVERIFY(drawer);
- drawer->setEdge(Qt::RightEdge);
+ QQuickItem *popupItem = drawer->popupItem();
+ QVERIFY(popupItem);
drawer->open();
- QTRY_COMPARE(drawer->popupItem()->x(), window->width() - drawer->width());
+ QQuickItem *dimmer = QQuickPopupPrivate::get(drawer)->dimmer;
+ QVERIFY(dimmer);
+
+ QCOMPARE(geometry(dimmer), QRectF(0, 0, window->width(), window->height()));
+ QTRY_COMPARE(geometry(popupItem), QRectF(0, 0, window->width() / 2, window->height()));
+
+ drawer->setY(100);
+ QCOMPARE(geometry(dimmer), QRectF(0, 100, window->width(), window->height() - 100));
+ QCOMPARE(geometry(popupItem), QRectF(0, 100, window->width() / 2, window->height() - 100));
+
+ drawer->setHeight(window->height());
+ QCOMPARE(geometry(dimmer), QRectF(0, 100, window->width(), window->height()));
+ QCOMPARE(geometry(popupItem), QRectF(0, 100, window->width() / 2, window->height()));
+
+ drawer->resetHeight();
+ QCOMPARE(geometry(dimmer), QRectF(0, 100, window->width(), window->height() - 100));
+ QCOMPARE(geometry(popupItem), QRectF(0, 100, window->width() / 2, window->height() - 100));
+
+ drawer->setParentItem(window->contentItem());
+ QCOMPARE(geometry(dimmer), QRectF(0, 150, window->width(), window->height() - 150));
+ QCOMPARE(geometry(popupItem), QRectF(0, 150, window->width() / 2, window->height() - 150));
+
+ drawer->setEdge(Qt::RightEdge);
+ QCOMPARE(geometry(dimmer), QRectF(0, 150, window->width(), window->height() - 150));
+ QTRY_COMPARE(geometry(popupItem), QRectF(window->width() - drawer->width(), 150, window->width() / 2, window->height() - 150));
window->setWidth(window->width() + 100);
- QTRY_COMPARE(drawer->popupItem()->x(), window->width() - drawer->width());
+ QTRY_COMPARE(geometry(dimmer), QRectF(0, 150, window->width(), window->height() - 150));
+ QCOMPARE(geometry(popupItem), QRectF(window->width() - drawer->width(), 150, window->width() / 2, window->height() - 150));
drawer->close();
- QTRY_COMPARE(drawer->popupItem()->x(), static_cast<qreal>(window->width()));
+ QTRY_COMPARE(geometry(popupItem), QRectF(window->width(), 150, window->width() / 2, window->height() - 150));
+}
+
+void tst_Drawer::header()
+{
+ QQuickApplicationHelper helper(this, QStringLiteral("header.qml"));
+
+ QQuickApplicationWindow *window = helper.appWindow;
+ window->show();
+ QVERIFY(QTest::qWaitForWindowExposed(window));
+
+ QQuickItem *content = window->contentItem();
+ QVERIFY(content);
+
+ QQuickOverlay *overlay = QQuickOverlay::overlay(window);
+ QVERIFY(overlay);
+
+ QQuickDrawer *drawer = window->property("drawer").value<QQuickDrawer*>();
+ QVERIFY(drawer);
+ QQuickItem *popupItem = drawer->popupItem();
+
+ drawer->open();
+ QVERIFY(drawer->isVisible());
+
+ QCOMPARE(drawer->parentItem(), overlay);
+ QCOMPARE(drawer->height(), overlay->height());
+ QCOMPARE(popupItem->height(), overlay->height());
+
+ drawer->setParentItem(content);
+ QCOMPARE(drawer->parentItem(), content);
+ QCOMPARE(drawer->height(), content->height());
+ QCOMPARE(popupItem->height(), content->height());
}
void tst_Drawer::hover_data()
@@ -615,6 +684,58 @@ void tst_Drawer::multiple()
QCOMPARE(leftDrawer->position(), 0.0);
}
+void tst_Drawer::touch_data()
+{
+ QTest::addColumn<QString>("source");
+ QTest::newRow("Window") << "window.qml";
+ QTest::newRow("ApplicationWindow") << "applicationwindow.qml";
+}
+
+void tst_Drawer::touch()
+{
+ QFETCH(QString, source);
+ QQuickApplicationHelper helper(this, source);
+
+ QQuickWindow *window = helper.window;
+ window->show();
+ QVERIFY(QTest::qWaitForWindowExposed(window));
+
+ QQuickDrawer *drawer = window->property("drawer").value<QQuickDrawer*>();
+ QVERIFY(drawer);
+
+ struct TouchDeviceDeleter
+ {
+ static inline void cleanup(QTouchDevice *device)
+ {
+ QWindowSystemInterface::unregisterTouchDevice(device);
+ delete device;
+ }
+ };
+
+ QScopedPointer<QTouchDevice, TouchDeviceDeleter> device(new QTouchDevice);
+ device->setType(QTouchDevice::TouchScreen);
+ QWindowSystemInterface::registerTouchDevice(device.data());
+
+ // drag to open
+ QTest::touchEvent(window, device.data()).press(0, QPoint(0, 100));
+ QTest::touchEvent(window, device.data()).move(0, QPoint(100, 100));
+ QTRY_COMPARE(drawer->position(), 0.5);
+ QTest::touchEvent(window, device.data()).release(0, QPoint(100, 100));
+ QTRY_COMPARE(drawer->position(), 1.0);
+
+ // drag to close
+ QTest::touchEvent(window, device.data()).press(0, QPoint(300, 100));
+ QTest::touchEvent(window, device.data()).move(0, QPoint(300 - drawer->dragMargin(), 100));
+ for (int x = 300; x > 100; x -= 10) {
+ QTest::touchEvent(window, device.data()).move(0, QPoint(x, 100));
+ QQuickWindowPrivate::get(window)->flushFrameSynchronousEvents();
+ }
+ QTest::touchEvent(window, device.data()).move(0, QPoint(100, 100));
+ QTRY_COMPARE(drawer->position(), 0.5);
+ QTest::touchEvent(window, device.data()).release(0, QPoint(100, 100));
+ QTRY_COMPARE(drawer->position(), 0.0);
+}
+
QTEST_MAIN(tst_Drawer)
#include "tst_drawer.moc"