aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/popup
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@qt.io>2016-09-06 16:59:39 +0200
committerJ-P Nurmi <jpnurmi@qt.io>2016-09-13 06:51:35 +0000
commitb3619f32c20b5851ada0826ec2e7ddc2ec8a210b (patch)
tree65c9332b68b808d8df984c6b325ede44c168b501 /tests/auto/popup
parentdb018c5cc71f5f62bcce7df4f2bed76b2899884d (diff)
Fix modal overlays leaking wheel events through
Change-Id: I1a3be5ef02cf73a153cebc030313f892fbb03d9f Task-number: QTBUG-55769 Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'tests/auto/popup')
-rw-r--r--tests/auto/popup/data/applicationwindow-wheel.qml71
-rw-r--r--tests/auto/popup/data/window-wheel.qml71
-rw-r--r--tests/auto/popup/tst_popup.cpp87
3 files changed, 229 insertions, 0 deletions
diff --git a/tests/auto/popup/data/applicationwindow-wheel.qml b/tests/auto/popup/data/applicationwindow-wheel.qml
new file mode 100644
index 00000000..a655713e
--- /dev/null
+++ b/tests/auto/popup/data/applicationwindow-wheel.qml
@@ -0,0 +1,71 @@
+/****************************************************************************
+**
+** 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.Window 2.2
+import QtQuick.Controls 2.0
+
+ApplicationWindow {
+ id: window
+ width: 400
+ height: 400
+
+ property alias popup: popup
+ property alias popupSlider: popupSlider
+ property alias contentSlider: contentSlider
+
+ Slider {
+ id: contentSlider
+ anchors.fill: parent
+ wheelEnabled: true
+ }
+
+ Popup {
+ id: popup
+ x: 50; y: 50
+ implicitWidth: parent.width - 100
+ implicitHeight: parent.height - 100
+ clip: true
+ contentItem: Slider {
+ id: popupSlider
+ wheelEnabled: true
+ }
+ }
+}
diff --git a/tests/auto/popup/data/window-wheel.qml b/tests/auto/popup/data/window-wheel.qml
new file mode 100644
index 00000000..2ffe4bf6
--- /dev/null
+++ b/tests/auto/popup/data/window-wheel.qml
@@ -0,0 +1,71 @@
+/****************************************************************************
+**
+** 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.Window 2.2
+import QtQuick.Controls 2.0
+
+Window {
+ id: window
+ width: 400
+ height: 400
+
+ property alias popup: popup
+ property alias popupSlider: popupSlider
+ property alias contentSlider: contentSlider
+
+ Slider {
+ id: contentSlider
+ anchors.fill: parent
+ wheelEnabled: true
+ }
+
+ Popup {
+ id: popup
+ x: 50; y: 50
+ implicitWidth: parent.width - 100
+ implicitHeight: parent.height - 100
+ clip: true
+ contentItem: Slider {
+ id: popupSlider
+ wheelEnabled: true
+ }
+ }
+}
diff --git a/tests/auto/popup/tst_popup.cpp b/tests/auto/popup/tst_popup.cpp
index a6848fc8..298328de 100644
--- a/tests/auto/popup/tst_popup.cpp
+++ b/tests/auto/popup/tst_popup.cpp
@@ -43,6 +43,7 @@
#include <QtQuickTemplates2/private/qquickoverlay_p.h>
#include <QtQuickTemplates2/private/qquickpopup_p.h>
#include <QtQuickTemplates2/private/qquickbutton_p.h>
+#include <QtQuickTemplates2/private/qquickslider_p.h>
using namespace QQuickVisualTestUtil;
@@ -65,6 +66,8 @@ private slots:
void activeFocusOnClose2();
void hover_data();
void hover();
+ void wheel_data();
+ void wheel();
void parentDestroyed();
};
@@ -514,6 +517,90 @@ void tst_popup::hover()
QVERIFY(parentButton->isHovered());
}
+void tst_popup::wheel_data()
+{
+ QTest::addColumn<QString>("source");
+ QTest::addColumn<bool>("modal");
+
+ QTest::newRow("Window:modal") << "window-wheel.qml" << true;
+ QTest::newRow("Window:modeless") << "window-wheel.qml" << false;
+ QTest::newRow("ApplicationWindow:modal") << "applicationwindow-wheel.qml" << true;
+ QTest::newRow("ApplicationWindow:modeless") << "applicationwindow-wheel.qml" << false;
+}
+
+static bool sendWheelEvent(QQuickItem *item, const QPoint &localPos, int degrees)
+{
+ QQuickWindow *window = item->window();
+ QWheelEvent wheelEvent(localPos, item->window()->mapToGlobal(localPos), QPoint(0, 0), QPoint(0, 8 * degrees), 0, Qt::Vertical, Qt::NoButton, 0);
+ QSpontaneKeyEvent::setSpontaneous(&wheelEvent);
+ return qGuiApp->notify(window, &wheelEvent);
+}
+
+void tst_popup::wheel()
+{
+ QFETCH(QString, source);
+ QFETCH(bool, modal);
+
+ QQuickApplicationHelper helper(this, source);
+ QQuickWindow *window = helper.window;
+ window->show();
+ QVERIFY(QTest::qWaitForWindowExposed(window));
+
+ QQuickSlider *contentSlider = window->property("contentSlider").value<QQuickSlider*>();
+ QVERIFY(contentSlider);
+
+ QQuickPopup *popup = window->property("popup").value<QQuickPopup*>();
+ QVERIFY(popup && popup->contentItem());
+ popup->setModal(modal);
+
+ QQuickSlider *popupSlider = window->property("popupSlider").value<QQuickSlider*>();
+ QVERIFY(popupSlider);
+
+ {
+ // wheel over the content
+ qreal oldContentValue = contentSlider->value();
+ qreal oldPopupValue = popupSlider->value();
+
+ QVERIFY(sendWheelEvent(contentSlider, QPoint(contentSlider->width() / 2, contentSlider->height() / 2), 15));
+
+ QVERIFY(!qFuzzyCompare(contentSlider->value(), oldContentValue)); // must have moved
+ QVERIFY(qFuzzyCompare(popupSlider->value(), oldPopupValue)); // must not have moved
+ }
+
+ QSignalSpy openedSpy(popup, SIGNAL(opened()));
+ QVERIFY(openedSpy.isValid());
+ popup->open();
+ QVERIFY(openedSpy.count() == 1 || openedSpy.wait());
+
+ {
+ // wheel over the popup content
+ qreal oldContentValue = contentSlider->value();
+ qreal oldPopupValue = popupSlider->value();
+
+ QVERIFY(sendWheelEvent(popupSlider, QPoint(popupSlider->width() / 2, popupSlider->height() / 2), 15));
+
+ QVERIFY(qFuzzyCompare(contentSlider->value(), oldContentValue)); // must not have moved
+ QVERIFY(!qFuzzyCompare(popupSlider->value(), oldPopupValue)); // must have moved
+ }
+
+ {
+ // wheel over the overlay
+ qreal oldContentValue = contentSlider->value();
+ qreal oldPopupValue = popupSlider->value();
+
+ QVERIFY(sendWheelEvent(QQuickOverlay::overlay(window), QPoint(0, 0), 15));
+
+ if (modal) {
+ // the content below a modal overlay must not move
+ QVERIFY(qFuzzyCompare(contentSlider->value(), oldContentValue));
+ } else {
+ // the content below a modeless overlay must move
+ QVERIFY(!qFuzzyCompare(contentSlider->value(), oldContentValue));
+ }
+ QVERIFY(qFuzzyCompare(popupSlider->value(), oldPopupValue)); // must not have moved
+ }
+}
+
void tst_popup::parentDestroyed()
{
QQuickPopup popup;