aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/quick
diff options
context:
space:
mode:
authorSami Nurmenniemi <sami.nurmenniemi@qt.io>2017-12-14 13:23:11 +0200
committerSami Nurmenniemi <sami.nurmenniemi@qt.io>2018-02-19 09:14:21 +0000
commit258f9e054b7b887985d7505107f59f1bd5acaf25 (patch)
tree3572cd88e1d3611600f5e699eb26913ae79999e8 /tests/auto/quick
parent6c8ac41508f985594aac643a2fd4ca75dfdeab98 (diff)
Add test for detecting invalid mouse button cancel event
Commit e0c30279ec1fad88346ed3fb483bc3c672fdd01b has already fixed the issue tested by this change. Task-number: QTBUG-60123 Change-Id: I0e378a7b1586f4e6c43246fca9d12719f62b3275 Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Diffstat (limited to 'tests/auto/quick')
-rw-r--r--tests/auto/quick/qquickitem/data/mainWindowQtBug60123.qml59
-rw-r--r--tests/auto/quick/qquickitem/qquickitem.pro5
-rw-r--r--tests/auto/quick/qquickitem/tst_qquickitem.cpp52
3 files changed, 116 insertions, 0 deletions
diff --git a/tests/auto/quick/qquickitem/data/mainWindowQtBug60123.qml b/tests/auto/quick/qquickitem/data/mainWindowQtBug60123.qml
new file mode 100644
index 0000000000..eeecd48cb2
--- /dev/null
+++ b/tests/auto/quick/qquickitem/data/mainWindowQtBug60123.qml
@@ -0,0 +1,59 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:GPL-EXCEPT$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQuick 2.0
+
+Rectangle {
+ width: 400
+ height: 200
+ color: "white"
+ property string lastEvent: ""
+
+ Rectangle {
+ id: buttonRect
+ width: 50
+ height: 50
+ color: "black"
+
+ MouseArea {
+ anchors.fill: parent
+ onPressed: {
+ lastEvent = "pressed"
+ buttonRect.color = "yellow"
+ }
+ onReleased: {
+ lastEvent = "released"
+ buttonRect.color = "black"
+ }
+ onCanceled: {
+ lastEvent = "canceled"
+ buttonRect.color = "green"
+ }
+ }
+ }
+}
diff --git a/tests/auto/quick/qquickitem/qquickitem.pro b/tests/auto/quick/qquickitem/qquickitem.pro
index 9aca5926f2..003981d4de 100644
--- a/tests/auto/quick/qquickitem/qquickitem.pro
+++ b/tests/auto/quick/qquickitem/qquickitem.pro
@@ -11,3 +11,8 @@ TESTDATA = data/*
QT += core-private gui-private qml-private quick-private testlib
+qtHaveModule(widgets): {
+ DEFINES += TEST_QTBUG_60123
+ QT += widgets
+}
+
diff --git a/tests/auto/quick/qquickitem/tst_qquickitem.cpp b/tests/auto/quick/qquickitem/tst_qquickitem.cpp
index f4434d9d3f..f5e8c6858a 100644
--- a/tests/auto/quick/qquickitem/tst_qquickitem.cpp
+++ b/tests/auto/quick/qquickitem/tst_qquickitem.cpp
@@ -41,6 +41,11 @@
#include "../shared/viewtestutil.h"
#include <QSignalSpy>
+#ifdef TEST_QTBUG_60123
+#include <QWidget>
+#include <QMainWindow>
+#endif
+
class TestItem : public QQuickItem
{
Q_OBJECT
@@ -188,6 +193,10 @@ private slots:
void shortcutOverride();
+#ifdef TEST_QTBUG_60123
+ void qtBug60123();
+#endif
+
private:
enum PaintOrderOp {
@@ -2092,6 +2101,49 @@ void tst_qquickitem::shortcutOverride()
QCOMPARE(view.rootObject()->property("shortcutActivationCount").toInt(), 1);
}
+#ifdef TEST_QTBUG_60123
+void tst_qquickitem::qtBug60123()
+{
+ QMainWindow main;
+
+ QQuickView window;
+ QQuickView window2;
+ window.setSource(testFileUrl("mainWindowQtBug60123.qml"));
+ window2.setSource(testFileUrl("mainWindowQtBug60123.qml"));
+
+ QWidget *baseWidget = new QWidget(&main);
+ main.resize(400, 200);
+ baseWidget->resize(400, 200);
+ baseWidget->setMaximumHeight(200);
+ baseWidget->setMaximumWidth(400);
+
+ // Create container widgets for both windows
+ QWidget *containers = QWidget::createWindowContainer(&window, baseWidget);
+ containers->setGeometry(0, 0, 400, 200);
+ QWidget* containers2 = QWidget::createWindowContainer(&window2, baseWidget);
+ containers2->setGeometry(50, 50, 300, 150);
+
+ // Show and activate the main window
+ main.show();
+ QTest::qWaitForWindowActive(&main);
+
+ // Activate window, test press and release events
+ auto activateWindowAndTestPress = [] (QQuickView* testWindow) {
+ testWindow->requestActivate();
+ QTest::qWaitForWindowActive(testWindow);
+ QTest::mousePress(testWindow, Qt::LeftButton, 0, QPoint(10, 10));
+ QCOMPARE(testWindow->rootObject()->property("lastEvent").toString(), QString("pressed"));
+ QTest::mouseRelease(testWindow, Qt::LeftButton, 0, QPoint(10, 10));
+ QCOMPARE(testWindow->rootObject()->property("lastEvent").toString(), QString("released"));
+ };
+
+ // First press after switching focus window resulted in cancelled event
+ activateWindowAndTestPress(&window);
+ activateWindowAndTestPress(&window2);
+ activateWindowAndTestPress(&window);
+}
+#endif
+
QTEST_MAIN(tst_qquickitem)
#include "tst_qquickitem.moc"