summaryrefslogtreecommitdiffstats
path: root/tests/auto/widgets/util
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/widgets/util')
-rw-r--r--tests/auto/widgets/util/CMakeLists.txt3
-rw-r--r--tests/auto/widgets/util/qcompleter/BLACKLIST4
-rw-r--r--tests/auto/widgets/util/qcompleter/CMakeLists.txt15
-rw-r--r--tests/auto/widgets/util/qcompleter/tst_qcompleter.cpp139
-rw-r--r--tests/auto/widgets/util/qscroller/CMakeLists.txt12
-rw-r--r--tests/auto/widgets/util/qscroller/tst_qscroller.cpp68
-rw-r--r--tests/auto/widgets/util/qsystemtrayicon/CMakeLists.txt17
-rw-r--r--tests/auto/widgets/util/qsystemtrayicon/tst_qsystemtrayicon.cpp14
8 files changed, 219 insertions, 53 deletions
diff --git a/tests/auto/widgets/util/CMakeLists.txt b/tests/auto/widgets/util/CMakeLists.txt
index 20accb3150..31725573c7 100644
--- a/tests/auto/widgets/util/CMakeLists.txt
+++ b/tests/auto/widgets/util/CMakeLists.txt
@@ -1,4 +1,5 @@
-# Generated from util.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
add_subdirectory(qcompleter)
add_subdirectory(qscroller)
diff --git a/tests/auto/widgets/util/qcompleter/BLACKLIST b/tests/auto/widgets/util/qcompleter/BLACKLIST
index 367270fdf2..5487a1fe44 100644
--- a/tests/auto/widgets/util/qcompleter/BLACKLIST
+++ b/tests/auto/widgets/util/qcompleter/BLACKLIST
@@ -1,6 +1,2 @@
[QTBUG_14292_filesystem]
-ubuntu-16.04
opensuse-leap
-rhel-7.4
-rhel-6.6
-opensuse-42.3
diff --git a/tests/auto/widgets/util/qcompleter/CMakeLists.txt b/tests/auto/widgets/util/qcompleter/CMakeLists.txt
index 5d4ff347a2..a96945771f 100644
--- a/tests/auto/widgets/util/qcompleter/CMakeLists.txt
+++ b/tests/auto/widgets/util/qcompleter/CMakeLists.txt
@@ -1,17 +1,22 @@
-# Generated from qcompleter.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qcompleter Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qcompleter LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qcompleter
SOURCES
tst_qcompleter.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::Gui
Qt::TestPrivate
Qt::Widgets
+ Qt::WidgetsPrivate
)
-
-#### Keys ignored in scope 1:.:.:qcompleter.pro:<TRUE>:
-# TEMPLATE = "app"
diff --git a/tests/auto/widgets/util/qcompleter/tst_qcompleter.cpp b/tests/auto/widgets/util/qcompleter/tst_qcompleter.cpp
index 897608bca8..b2e77bc935 100644
--- a/tests/auto/widgets/util/qcompleter/tst_qcompleter.cpp
+++ b/tests/auto/widgets/util/qcompleter/tst_qcompleter.cpp
@@ -1,11 +1,10 @@
// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
#include <QtGui>
#include <QtWidgets>
#include <QtDebug>
-#include <QPair>
#include <QList>
#include <QPointer>
#include <QSignalSpy>
@@ -16,6 +15,8 @@
#include <memory>
+#include <QtWidgets/private/qapplication_p.h>
+
Q_DECLARE_METATYPE(QCompleter::CompletionMode)
using namespace QTestPrivate;
@@ -57,7 +58,7 @@ QString CsvCompleter::pathFromIndex(const QModelIndex &sourceIndex) const
idx = parent.sibling(parent.row(), sourceIndex.column());
} while (idx.isValid());
- return list.count() == 1 ? list.constFirst() : list.join(QLatin1Char(','));
+ return list.size() == 1 ? list.constFirst() : list.join(QLatin1Char(','));
}
class tst_QCompleter : public QObject
@@ -108,6 +109,8 @@ private slots:
void dynamicSortOrder();
void disabledItems();
+ void hideWidget();
+
// task-specific tests below me
void task178797_activatedOnReturn();
void task189564_omitNonSelectableItems();
@@ -121,6 +124,7 @@ private slots:
void QTBUG_52028_tabAutoCompletes();
void QTBUG_51889_activatedSentTwice();
void showPopupInGraphicsView();
+ void inheritedEventFilter();
private:
void filter(bool assync = false);
@@ -151,6 +155,16 @@ tst_QCompleter::~tst_QCompleter()
delete completer;
}
+#ifdef Q_OS_ANDROID
+static QString androidHomePath()
+{
+ const auto homePaths = QStandardPaths::standardLocations(QStandardPaths::HomeLocation);
+ QDir dir = homePaths.isEmpty() ? QDir() : homePaths.first();
+ dir.cdUp();
+ return dir.path();
+}
+#endif
+
void tst_QCompleter::setSourceModel(ModelType type)
{
QTreeWidgetItem *parent, *child;
@@ -203,7 +217,13 @@ void tst_QCompleter::setSourceModel(ModelType type)
completer->setCsvCompletion(false);
{
auto m = new QFileSystemModel(completer);
+#ifdef Q_OS_ANDROID
+ // Android 11 and above doesn't allow accessing root filesystem as before,
+ // so let's opt int for the app's home.
+ m->setRootPath(androidHomePath());
+#else
m->setRootPath("/");
+#endif
completer->setModel(m);
}
completer->setCompletionColumn(0);
@@ -590,7 +610,9 @@ void tst_QCompleter::fileSystemModel_data()
// QTest::newRow("(/d)") << "/d" << "" << "Developer" << "/Developer";
#elif defined(Q_OS_ANDROID)
QTest::newRow("()") << "" << "" << "/" << "/";
- QTest::newRow("(/et)") << "/et" << "" << "etc" << "/etc";
+ const QString androidDir = androidHomePath();
+ const QString tag = QStringLiteral("%1/fil").arg(androidDir);
+ QTest::newRow(tag.toUtf8().data()) << tag << "" << "files" << androidDir + "/files";
#else
QTest::newRow("()") << "" << "" << "/" << "/";
#if !defined(Q_OS_AIX) && !defined(Q_OS_HPUX) && !defined(Q_OS_QNX)
@@ -1040,7 +1062,6 @@ void tst_QCompleter::multipleWidgets()
window.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
window.move(200, 200);
window.show();
- QApplication::setActiveWindow(&window);
QVERIFY(QTest::qWaitForWindowActive(&window));
QFocusEvent focusIn(QEvent::FocusIn);
@@ -1052,7 +1073,6 @@ void tst_QCompleter::multipleWidgets()
comboBox->setFocus();
comboBox->show();
window.activateWindow();
- QApplication::setActiveWindow(&window);
QVERIFY(QTest::qWaitForWindowActive(&window));
QCOMPARE(QApplication::focusWidget(), comboBox);
comboBox->lineEdit()->setText("it");
@@ -1087,7 +1107,6 @@ void tst_QCompleter::focusIn()
window.move(200, 200);
window.show();
window.activateWindow();
- QApplication::setActiveWindow(&window);
QVERIFY(QTest::qWaitForWindowActive(&window));
auto comboBox = new QComboBox(&window);
@@ -1158,13 +1177,39 @@ void tst_QCompleter::disabledItems()
QAbstractItemView *view = lineEdit.completer()->popup();
QVERIFY(view->isVisible());
QTest::mouseClick(view->viewport(), Qt::LeftButton, {}, view->visualRect(view->model()->index(0, 0)).center());
- QCOMPARE(spy.count(), 0);
+ QCOMPARE(spy.size(), 0);
QVERIFY(view->isVisible());
QTest::mouseClick(view->viewport(), Qt::LeftButton, {}, view->visualRect(view->model()->index(1, 0)).center());
- QCOMPARE(spy.count(), 1);
+ QCOMPARE(spy.size(), 1);
QVERIFY(!view->isVisible());
}
+void tst_QCompleter::hideWidget()
+{
+ // hiding the widget should hide/close the popup
+ QWidget w;
+ w.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
+ w.setLayout(new QVBoxLayout);
+
+ QLineEdit edit;
+ edit.setCompleter(new QCompleter({ "foo", "bar" }));
+
+ w.layout()->addWidget(&edit);
+
+ const auto pos = w.screen()->availableGeometry().topLeft() + QPoint(200, 200);
+ w.move(pos);
+ w.show();
+ QApplicationPrivate::setActiveWindow(&w);
+ QVERIFY(QTest::qWaitForWindowActive(&w));
+
+ // activate the completer
+ QTest::keyClick(&edit, Qt::Key_F);
+ QVERIFY(edit.completer()->popup());
+ QTRY_VERIFY(edit.completer()->popup()->isVisible());
+ edit.hide();
+ QVERIFY(!edit.completer()->popup()->isVisible());
+}
+
void tst_QCompleter::task178797_activatedOnReturn()
{
if (QGuiApplication::platformName().startsWith(QLatin1String("wayland"), Qt::CaseInsensitive))
@@ -1175,10 +1220,9 @@ void tst_QCompleter::task178797_activatedOnReturn()
auto completer = new QCompleter({"foobar1", "foobar2"}, &ledit);
ledit.setCompleter(completer);
QSignalSpy spy(completer, QOverload<const QString &>::of(&QCompleter::activated));
- QCOMPARE(spy.count(), 0);
+ QCOMPARE(spy.size(), 0);
ledit.move(200, 200);
ledit.show();
- QApplication::setActiveWindow(&ledit);
QVERIFY(QTest::qWaitForWindowActive(&ledit));
QTest::keyClick(&ledit, Qt::Key_F);
QCoreApplication::processEvents();
@@ -1187,7 +1231,7 @@ void tst_QCompleter::task178797_activatedOnReturn()
QCoreApplication::processEvents();
QTest::keyClick(QApplication::activePopupWidget(), Qt::Key_Return);
QCoreApplication::processEvents();
- QCOMPARE(spy.count(), 1);
+ QCOMPARE(spy.size(), 1);
}
class task189564_StringListModel : public QStringListModel
@@ -1262,14 +1306,13 @@ void tst_QCompleter::task246056_setCompletionPrefix()
comboBox.addItem("a2");
comboBox.move(200, 200);
comboBox.show();
- QApplication::setActiveWindow(&comboBox);
QVERIFY(QTest::qWaitForWindowActive(&comboBox));
QSignalSpy spy(comboBox.completer(), QOverload<const QModelIndex &>::of(&QCompleter::activated));
QTest::keyPress(&comboBox, 'a');
QTest::keyPress(comboBox.completer()->popup(), Qt::Key_Down);
QTest::keyPress(comboBox.completer()->popup(), Qt::Key_Down);
QTest::keyPress(comboBox.completer()->popup(), Qt::Key_Enter); // don't crash!
- QCOMPARE(spy.count(), 1);
+ QCOMPARE(spy.size(), 1);
const auto index = spy.at(0).constFirst().toModelIndex();
QVERIFY(!index.isValid());
}
@@ -1328,7 +1371,6 @@ void tst_QCompleter::task250064_lostFocus()
task250064_Widget widget;
widget.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
widget.show();
- QApplication::setActiveWindow(&widget);
QVERIFY(QTest::qWaitForWindowActive(&widget));
QTest::keyPress(widget.textEdit(), 'a');
Qt::FocusPolicy origPolicy = widget.textEdit()->focusPolicy();
@@ -1373,7 +1415,6 @@ void tst_QCompleter::task253125_lineEditCompletion()
edit.move(200, 200);
edit.show();
edit.setFocus();
- QApplication::setActiveWindow(&edit);
QVERIFY(QTest::qWaitForWindowActive(&edit));
QTest::keyClick(&edit, 'i');
@@ -1536,7 +1577,6 @@ void tst_QCompleter::task247560_keyboardNavigation()
edit.move(200, 200);
edit.show();
edit.setFocus();
- QApplication::setActiveWindow(&edit);
QVERIFY(QTest::qWaitForWindowActive(&edit));
QTest::keyClick(&edit, 'r');
@@ -1636,6 +1676,7 @@ void tst_QCompleter::QTBUG_14292_filesystem()
// to pop up the completion list due to file changed signals.
FileSystem fs;
QFileSystemModel model;
+ QSignalSpy filesAddedSpy(&model, &QAbstractItemModel::rowsInserted);
model.setRootPath(fs.path());
QVERIFY(fs.createDirectory(QLatin1String(testDir1)));
@@ -1649,7 +1690,6 @@ void tst_QCompleter::QTBUG_14292_filesystem()
edit.move(200, 200);
edit.show();
- QApplication::setActiveWindow(&edit);
QVERIFY(QTest::qWaitForWindowActive(&edit));
QCOMPARE(QApplication::activeWindow(), &edit);
edit.setFocus();
@@ -1665,6 +1705,7 @@ void tst_QCompleter::QTBUG_14292_filesystem()
QTRY_VERIFY(comp.popup()->isVisible());
QCOMPARE(comp.popup()->model()->rowCount(), 2);
QApplication::processEvents();
+ QCOMPARE(qApp->focusObject(), &edit); // for QTBUG_108522
QTest::keyClick(&edit, 'h');
QCOMPARE(comp.popup()->model()->rowCount(), 2);
QTest::keyClick(&edit, 'e');
@@ -1672,13 +1713,16 @@ void tst_QCompleter::QTBUG_14292_filesystem()
QTest::keyClick(&edit, 'r');
QTRY_VERIFY(!comp.popup()->isVisible());
QVERIFY(fs.createDirectory(QStringLiteral("hero")));
+ if (!filesAddedSpy.wait())
+ QSKIP("File system model didn't notify about new directory, skipping tests");
QTRY_VERIFY(comp.popup()->isVisible());
QCOMPARE(comp.popup()->model()->rowCount(), 1);
QTest::keyClick(comp.popup(), Qt::Key_Escape);
QTRY_VERIFY(!comp.popup()->isVisible());
QVERIFY(fs.createDirectory(QStringLiteral("nothingThere")));
//there is no reason creating a file should open a popup, it did in Qt 4.7.0
- QTest::qWait(60);
+ if (!filesAddedSpy.wait())
+ QSKIP("File system model didn't notify about new file, skipping tests");
QVERIFY(!comp.popup()->isVisible());
QTest::keyClick(&edit, Qt::Key_Backspace);
@@ -1690,13 +1734,13 @@ void tst_QCompleter::QTBUG_14292_filesystem()
QWidget w;
w.move(400, 200);
w.show();
- QApplication::setActiveWindow(&w);
QVERIFY(QTest::qWaitForWindowActive(&w));
QVERIFY(!edit.hasFocus() && !comp.popup()->hasFocus());
QVERIFY(fs.createDirectory(QStringLiteral("hemo")));
//there is no reason creating a file should open a popup, it did in Qt 4.7.0
- QTest::qWait(60);
+ if (!filesAddedSpy.wait())
+ QSKIP("File system model didn't notify about new file, skipping tests");
QVERIFY(!comp.popup()->isVisible());
}
@@ -1726,7 +1770,7 @@ void tst_QCompleter::QTBUG_52028_tabAutoCompletes()
const auto pos = w.screen()->availableGeometry().topLeft() + QPoint(200,200);
w.move(pos);
w.show();
- QApplication::setActiveWindow(&w);
+ QApplicationPrivate::setActiveWindow(&w);
QVERIFY(QTest::qWaitForWindowActive(&w));
QSignalSpy activatedSpy(&cbox, &QComboBox::activated);
@@ -1738,10 +1782,10 @@ void tst_QCompleter::QTBUG_52028_tabAutoCompletes()
QTRY_VERIFY(cbox.completer()->popup()->isVisible());
QTest::keyClick(cbox.completer()->popup(), Qt::Key_Tab);
QCOMPARE(cbox.completer()->currentCompletion(), QLatin1String("hux"));
- QCOMPARE(activatedSpy.count(), 0);
+ QCOMPARE(activatedSpy.size(), 0);
QEXPECT_FAIL("", "QTBUG-52028 will not be fixed today.", Abort);
QCOMPARE(cbox.currentText(), QLatin1String("hux"));
- QCOMPARE(activatedSpy.count(), 0);
+ QCOMPARE(activatedSpy.size(), 0);
QVERIFY(!le->hasFocus());
}
@@ -1770,7 +1814,6 @@ void tst_QCompleter::QTBUG_51889_activatedSentTwice()
const auto pos = w.screen()->availableGeometry().topLeft() + QPoint(200,200);
w.move(pos);
w.show();
- QApplication::setActiveWindow(&w);
QVERIFY(QTest::qWaitForWindowActive(&w));
QSignalSpy activatedSpy(&cbox, &QComboBox::activated);
@@ -1782,7 +1825,7 @@ void tst_QCompleter::QTBUG_51889_activatedSentTwice()
QTRY_VERIFY(cbox.completer()->popup()->isVisible());
QTest::keyClick(cbox.completer()->popup(), Qt::Key_Down);
QTest::keyClick(cbox.completer()->popup(), Qt::Key_Return);
- QTRY_COMPARE(activatedSpy.count(), 1);
+ QTRY_COMPARE(activatedSpy.size(), 1);
// Navigate + enter activates only once (non-first item)
cbox.lineEdit()->clear();
@@ -1792,7 +1835,7 @@ void tst_QCompleter::QTBUG_51889_activatedSentTwice()
QTRY_VERIFY(cbox.completer()->popup()->isVisible());
QTest::keyClick(cbox.completer()->popup(), Qt::Key_Down);
QTest::keyClick(cbox.completer()->popup(), Qt::Key_Return);
- QTRY_COMPARE(activatedSpy.count(), 1);
+ QTRY_COMPARE(activatedSpy.size(), 1);
// Full text + enter activates only once
cbox.lineEdit()->clear();
@@ -1801,11 +1844,14 @@ void tst_QCompleter::QTBUG_51889_activatedSentTwice()
QVERIFY(cbox.completer()->popup());
QTRY_VERIFY(cbox.completer()->popup()->isVisible());
QTest::keyClick(&cbox, Qt::Key_Return);
- QTRY_COMPARE(activatedSpy.count(), 1);
+ QTRY_COMPARE(activatedSpy.size(), 1);
}
void tst_QCompleter::showPopupInGraphicsView()
{
+ if (QGuiApplication::platformName().startsWith(QLatin1String("wayland"), Qt::CaseInsensitive))
+ QSKIP("Wayland: Skip this test, see also QTBUG-107186");
+
QGraphicsView view;
QGraphicsScene scene;
view.setScene(&scene);
@@ -1835,5 +1881,42 @@ void tst_QCompleter::showPopupInGraphicsView()
QVERIFY(lineEdit.completer()->popup()->geometry().bottom() < lineEdit.mapToGlobal(QPoint(0, 0)).y());
}
+void tst_QCompleter::inheritedEventFilter()
+{
+ class Completer : public QCompleter
+ {
+ public:
+ explicit Completer(QWidget *parent) : QCompleter(parent)
+ {
+ Q_ASSERT(parent);
+ setPopup(new QListView());
+ popup()->installEventFilter(this);
+ }
+
+ bool m_popupChildAdded = false;
+
+ protected:
+ bool eventFilter(QObject *watched, QEvent *event) override
+ {
+ if (watched == popup() && event->type() == QEvent::ChildAdded)
+ m_popupChildAdded = true;
+
+ return QCompleter::eventFilter(watched, event);
+ }
+ };
+
+ QComboBox comboBox;
+ comboBox.setEditable(true);
+ Completer *completer = new Completer(&comboBox);
+ comboBox.setCompleter(completer);
+
+ // comboBox.show() must not crash with an infinite loop in the event filter
+ comboBox.show();
+ QVERIFY(QTest::qWaitForWindowExposed(&comboBox));
+
+ // Since event orders are platform dependent, only the the ChildAdded event is checked.
+ QVERIFY(QTest::qWaitFor([completer](){return completer->m_popupChildAdded; }));
+}
+
QTEST_MAIN(tst_QCompleter)
#include "tst_qcompleter.moc"
diff --git a/tests/auto/widgets/util/qscroller/CMakeLists.txt b/tests/auto/widgets/util/qscroller/CMakeLists.txt
index 11e13cdd9f..2beee70109 100644
--- a/tests/auto/widgets/util/qscroller/CMakeLists.txt
+++ b/tests/auto/widgets/util/qscroller/CMakeLists.txt
@@ -1,14 +1,22 @@
-# Generated from qscroller.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qscroller Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qscroller LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
qt_internal_add_test(tst_qscroller
SOURCES
tst_qscroller.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::Gui
Qt::GuiPrivate
Qt::Widgets
+ Qt::WidgetsPrivate
)
diff --git a/tests/auto/widgets/util/qscroller/tst_qscroller.cpp b/tests/auto/widgets/util/qscroller/tst_qscroller.cpp
index 491d5d48e3..101b502fc6 100644
--- a/tests/auto/widgets/util/qscroller/tst_qscroller.cpp
+++ b/tests/auto/widgets/util/qscroller/tst_qscroller.cpp
@@ -1,5 +1,5 @@
// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QtGui>
#include <QtWidgets>
@@ -8,6 +8,8 @@
#include <QtGui/private/qeventpoint_p.h>
#include <qpa/qwindowsysteminterface.h>
+#include <QtWidgets/private/qapplication_p.h>
+
// #include <QDebug>
class tst_QScrollerWidget : public QWidget
@@ -103,6 +105,7 @@ private slots:
void scroll();
void overshoot();
void multipleWindows();
+ void mouseEventTimestamp();
private:
QPointingDevice *m_touchScreen = QTest::createTouchDevice();
@@ -321,7 +324,6 @@ void tst_QScroller::scrollTo()
{
QScopedPointer<tst_QScrollerWidget> sw(new tst_QScrollerWidget);
sw->show();
- QApplication::setActiveWindow(sw.data());
if (!QTest::qWaitForWindowExposed(sw.data()) || !QTest::qWaitForWindowActive(sw.data()))
QSKIP("Failed to show and activate window");
@@ -353,7 +355,6 @@ void tst_QScroller::scroll()
QScroller::grabGesture(sw.data(), QScroller::TouchGesture);
sw->setGeometry(100, 100, 400, 300);
sw->show();
- QApplication::setActiveWindow(sw.data());
if (!QTest::qWaitForWindowExposed(sw.data()) || !QTest::qWaitForWindowActive(sw.data()))
QSKIP("Failed to show and activate window");
@@ -394,7 +395,6 @@ void tst_QScroller::overshoot()
QScroller::grabGesture(sw.data(), QScroller::TouchGesture);
sw->setGeometry(100, 100, 400, 300);
sw->show();
- QApplication::setActiveWindow(sw.data());
if (!QTest::qWaitForWindowExposed(sw.data()) || !QTest::qWaitForWindowActive(sw.data()))
QSKIP("Failed to show and activate window");
@@ -516,6 +516,66 @@ void tst_QScroller::multipleWindows()
#endif
}
+/*!
+ This test verifies that mouse events arrive at the target widget
+ with valid timestamp, even if there is a gesture filtering (and then
+ replaying a copy of) the event. QTBUG-102010
+
+ We cannot truly simulate the double click here, as simulated events don't
+ go through the exact same event machinery as real events, so double clicks
+ don't get generated by Qt here. But we can verify that the timestamps of
+ the eventually delivered events are maintained.
+*/
+void tst_QScroller::mouseEventTimestamp()
+{
+#if QT_CONFIG(gestures) && QT_CONFIG(scroller)
+ QScopedPointer<tst_QScrollerWidget> sw(new tst_QScrollerWidget());
+ sw->scrollArea = QRectF(0, 0, 1000, 1000);
+ QScroller::grabGesture(sw.data(), QScroller::LeftMouseButtonGesture);
+ sw->setGeometry(100, 100, 400, 300);
+ sw->show();
+ if (!QTest::qWaitForWindowExposed(sw.data()) || !QTest::qWaitForWindowActive(sw.data()))
+ QSKIP("Failed to show and activate window");
+
+ QScroller *s1 = QScroller::scroller(sw.data());
+
+ struct EventFilter : QObject
+ {
+ QList<int> timestamps;
+ protected:
+ bool eventFilter(QObject *o, QEvent *e) override
+ {
+ if (e->isInputEvent())
+ timestamps << static_cast<QInputEvent *>(e)->timestamp();
+ return QObject::eventFilter(o, e);
+ }
+
+ } eventFilter;
+ sw->installEventFilter(&eventFilter);
+
+ const int interval = QGuiApplication::styleHints()->mouseDoubleClickInterval() / 10;
+ const QPoint point = sw->geometry().center();
+ // Simulate double by pressing twice within the double click interval.
+ // Presses are filtered and then delayed by the scroller/gesture machinery,
+ // so we first record all events, and then make sure that the relative timestamps
+ // are maintained also for the replayed or synthesized events.
+ QTest::mousePress(sw->windowHandle(), Qt::LeftButton, {}, point);
+ QCOMPARE(s1->state(), QScroller::Pressed);
+ QTest::mouseRelease(sw->windowHandle(), Qt::LeftButton, {}, point, interval);
+ QCOMPARE(s1->state(), QScroller::Inactive);
+ QTest::mousePress(sw->windowHandle(), Qt::LeftButton, {}, point, interval);
+ QCOMPARE(s1->state(), QScroller::Pressed);
+ // also filtered and delayed by the scroller
+ QTest::mouseRelease(sw->windowHandle(), Qt::LeftButton, {}, point, interval);
+ QCOMPARE(s1->state(), QScroller::Inactive);
+ int lastTimestamp = -1;
+ for (int timestamp : std::as_const(eventFilter.timestamps)) {
+ QCOMPARE_GE(timestamp, lastTimestamp);
+ lastTimestamp = timestamp + interval;
+ }
+#endif
+}
+
QTEST_MAIN(tst_QScroller)
#include "tst_qscroller.moc"
diff --git a/tests/auto/widgets/util/qsystemtrayicon/CMakeLists.txt b/tests/auto/widgets/util/qsystemtrayicon/CMakeLists.txt
index d84f229c04..d4c517e88c 100644
--- a/tests/auto/widgets/util/qsystemtrayicon/CMakeLists.txt
+++ b/tests/auto/widgets/util/qsystemtrayicon/CMakeLists.txt
@@ -1,13 +1,26 @@
-# Generated from qsystemtrayicon.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qsystemtrayicon Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qsystemtrayicon LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
+set(resources_resource_files
+ "icons/icon.png"
+)
+
qt_internal_add_test(tst_qsystemtrayicon
SOURCES
tst_qsystemtrayicon.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::Gui
Qt::Widgets
+ TESTDATA ${resources_resource_files}
+ BUILTIN_TESTDATA
)
diff --git a/tests/auto/widgets/util/qsystemtrayicon/tst_qsystemtrayicon.cpp b/tests/auto/widgets/util/qsystemtrayicon/tst_qsystemtrayicon.cpp
index 5348942857..9a7cd2e534 100644
--- a/tests/auto/widgets/util/qsystemtrayicon/tst_qsystemtrayicon.cpp
+++ b/tests/auto/widgets/util/qsystemtrayicon/tst_qsystemtrayicon.cpp
@@ -1,5 +1,5 @@
// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QTest>
@@ -39,9 +39,9 @@ tst_QSystemTrayIcon::~tst_QSystemTrayIcon()
void tst_QSystemTrayIcon::showHide()
{
QSystemTrayIcon icon;
- icon.setIcon(QIcon("icons/icon.png"));
+ icon.setIcon(QIcon(":/icons/icon.png"));
icon.show();
- icon.setIcon(QIcon("icons/icon.png"));
+ icon.setIcon(QIcon(":/icons/icon.png"));
icon.hide();
}
@@ -49,7 +49,7 @@ void tst_QSystemTrayIcon::showHide()
void tst_QSystemTrayIcon::showMessage()
{
QSystemTrayIcon icon;
- icon.setIcon(QIcon("icons/icon.png"));
+ icon.setIcon(QIcon(":/icons/icon.png"));
icon.showMessage("Title", "Messagecontents");
icon.showMessage("Title", "Messagecontents", QSystemTrayIcon::NoIcon);
@@ -72,7 +72,7 @@ void tst_QSystemTrayIcon::getSetCheck()
QCOMPARE(true, "testToolTip" == icon.toolTip());
QCOMPARE(true, icon.icon().isNull());
- icon.setIcon(QIcon("icons/icon.png"));
+ icon.setIcon(QIcon(":/icons/icon.png"));
QCOMPARE(false, icon.icon().isNull());
QMenu menu;
@@ -104,13 +104,13 @@ void tst_QSystemTrayIcon::lastWindowClosed()
QSignalSpy spy(qApp, &QGuiApplication::lastWindowClosed);
QWidget window;
QSystemTrayIcon icon;
- icon.setIcon(QIcon("whatever.png"));
+ icon.setIcon(QIcon(":/icons/icon.png"));
icon.show();
window.show();
QTimer::singleShot(2500, &window, SLOT(close()));
QTimer::singleShot(20000, qApp, SLOT(quit())); // in case the test fails
qApp->exec();
- QCOMPARE(spy.count(), 1);
+ QCOMPARE(spy.size(), 1);
}
QTEST_MAIN(tst_QSystemTrayIcon)