From 258f9e054b7b887985d7505107f59f1bd5acaf25 Mon Sep 17 00:00:00 2001 From: Sami Nurmenniemi Date: Thu, 14 Dec 2017 13:23:11 +0200 Subject: 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 --- .../quick/qquickitem/data/mainWindowQtBug60123.qml | 59 ++++++++++++++++++++++ tests/auto/quick/qquickitem/qquickitem.pro | 5 ++ tests/auto/quick/qquickitem/tst_qquickitem.cpp | 52 +++++++++++++++++++ 3 files changed, 116 insertions(+) create mode 100644 tests/auto/quick/qquickitem/data/mainWindowQtBug60123.qml (limited to 'tests/auto') 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 +#ifdef TEST_QTBUG_60123 +#include +#include +#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" -- cgit v1.2.3