diff options
| -rw-r--r-- | src/qml/jsapi/qjsengine.cpp | 4 | ||||
| -rw-r--r-- | tests/auto/qml/debugger/qqmlpreview/data/input.qml | 25 | ||||
| -rw-r--r-- | tests/auto/qml/debugger/qqmlpreview/tst_qqmlpreview.cpp | 75 |
3 files changed, 94 insertions, 10 deletions
diff --git a/src/qml/jsapi/qjsengine.cpp b/src/qml/jsapi/qjsengine.cpp index e76d7b6507..b847160e51 100644 --- a/src/qml/jsapi/qjsengine.cpp +++ b/src/qml/jsapi/qjsengine.cpp @@ -1275,6 +1275,10 @@ void QJSEnginePrivate::addToDebugServer(QJSEngine *q) if (!server || server->hasEngine(q)) return; + // Initialize the type loader before attaching debug services. We'll need it anyway and + // we don't want the preview service to block on resolving some paths from QLibraryInfo. + QQmlTypeLoader::get(q); + server->open(); server->addEngine(q); } diff --git a/tests/auto/qml/debugger/qqmlpreview/data/input.qml b/tests/auto/qml/debugger/qqmlpreview/data/input.qml new file mode 100644 index 0000000000..b310c146e8 --- /dev/null +++ b/tests/auto/qml/debugger/qqmlpreview/data/input.qml @@ -0,0 +1,25 @@ +// Copyright (C) 2025 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +import QtQuick + +Window { + id: window + visible: true + width: 100 + height: 100 + title: "aaa" + color: "blue" + + Timer { + repeat: true + interval: 200 + running: true + onTriggered: console.log(window.title, window.color) + } + + MouseArea { + anchors.fill: parent + onClicked: color = "red" + } +} diff --git a/tests/auto/qml/debugger/qqmlpreview/tst_qqmlpreview.cpp b/tests/auto/qml/debugger/qqmlpreview/tst_qqmlpreview.cpp index 201d57663a..e17c071a3c 100644 --- a/tests/auto/qml/debugger/qqmlpreview/tst_qqmlpreview.cpp +++ b/tests/auto/qml/debugger/qqmlpreview/tst_qqmlpreview.cpp @@ -1,9 +1,15 @@ // Copyright (C) 2018 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only -#include <qqmldebugprocess_p.h> -#include <debugutil_p.h> -#include <qqmlpreviewblacklist.h> +#include "debugutil_p.h" +#include "qqmldebugprocess_p.h" +#include "qqmlpreviewblacklist.h" + +#include <private/qqmldebugconnection_p.h> +#include <private/qqmlpreviewclient_p.h> +#include <private/qqmlprofilerclient_p.h> +#include <private/qqmlprofilerqtdwriter_p.h> +#include <private/qquickeventreplayclient_p.h> #include <QtTest/qtest.h> #include <QtTest/qsignalspy.h> @@ -13,9 +19,6 @@ #include <QtCore/qlibraryinfo.h> #include <QtNetwork/qhostaddress.h> -#include <private/qqmldebugconnection_p.h> -#include <private/qqmlpreviewclient_p.h> - class tst_QQmlPreview : public QQmlDebugTest { Q_OBJECT @@ -32,6 +35,9 @@ private: void verifyProcessOutputContains(const QString &string) const; QPointer<QQmlPreviewClient> m_client; + QPointer<QQmlProfilerQtdWriter> m_qtdWriter; + QPointer<QQmlProfilerClient> m_profiler; + QPointer<QQuickEventReplayClient> m_replay; QStringList m_files; QStringList m_filesNotFound; @@ -55,6 +61,7 @@ private slots: void updateFile(); void qqcStyleSelection(); void singleton(); + void handleInput(); }; tst_QQmlPreview::tst_QQmlPreview() @@ -64,8 +71,10 @@ tst_QQmlPreview::tst_QQmlPreview() QQmlDebugTest::ConnectResult tst_QQmlPreview::startQmlProcess(const QString &qmlFile, QStringList environmentVariables) { - return QQmlDebugTest::connectTo(QLibraryInfo::path(QLibraryInfo::BinariesPath) + "/qml", - QStringLiteral("QmlPreview"), testFile(qmlFile), true, environmentVariables); + return QQmlDebugTest::connectTo( + QLibraryInfo::path(QLibraryInfo::BinariesPath) + "/qml", + QStringLiteral("QmlPreview,CanvasFrameRate,EventReplay,EngineControl"), + testFile(qmlFile), true, environmentVariables); } void tst_QQmlPreview::serveRequest(const QString &path) @@ -95,6 +104,9 @@ void tst_QQmlPreview::serveFile(const QString &path, const QByteArray &contents) QList<QQmlDebugClient *> tst_QQmlPreview::createClients() { m_client = new QQmlPreviewClient(m_connection); + m_qtdWriter = new QQmlProfilerQtdWriter(m_connection); + m_profiler = new QQmlProfilerClient(m_connection, m_qtdWriter, 1 << ProfileInputEvents); + m_replay = new QQuickEventReplayClient(m_connection); QObject::connect(m_client.data(), &QQmlPreviewClient::request, this, &tst_QQmlPreview::serveRequest); QObject::connect(m_client.data(), &QQmlPreviewClient::error, this, [this](const QString &error) { @@ -105,7 +117,7 @@ QList<QQmlDebugClient *> tst_QQmlPreview::createClients() m_frameStats = info; }); - return QList<QQmlDebugClient *>({m_client}); + return QList<QQmlDebugClient *>({m_client, m_profiler, m_replay}); } void tst_QQmlPreview::verifyProcessOutputContains(const QString &string) const @@ -182,7 +194,8 @@ void tst_QQmlPreview::loadFromQrc() QCOMPARE(QQmlDebugTest::connectTo( QLibraryInfo::path(QLibraryInfo::BinariesPath) + "/qml", - QStringLiteral("QmlPreview"), fromQrc, true), + QStringLiteral("QmlPreview,CanvasFrameRate,EventReplay,EngineControl"), + fromQrc, true), ConnectSuccess); QVERIFY(m_client); @@ -468,6 +481,48 @@ void tst_QQmlPreview::singleton() QVERIFY(m_serviceErrors.isEmpty()); } +void tst_QQmlPreview::handleInput() +{ + const QString file("input.qml"); + QCOMPARE(startQmlProcess(file), ConnectSuccess); + QVERIFY(m_client); + QTRY_COMPARE(m_client->state(), QQmlDebugClient::Enabled); + m_client->triggerLoad(testFileUrl(file)); + QTRY_VERIFY(m_files.contains(testFile(file))); + verifyProcessOutputContains("aaa #0000ff"); + + const QQmlProfilerEventType mouseType {Event, MaximumRangeType, Mouse}; + const QList<QQmlProfilerEvent> clickEvents {{ + 0ll, 0, QList<int>({InputMouseMove, 12, 13}) + }, { + 1ll, 0, QList<int>({InputMousePress, Qt::LeftButton, Qt::LeftButton}) + }, { + 2ll, 0, QList<int>({InputMouseRelease, Qt::LeftButton, Qt::NoButton}) + }}; + + for (const QQmlProfilerEvent &event : clickEvents) + m_replay->sendEvent(mouseType, event); + + verifyProcessOutputContains("aaa #ff0000"); + + QFile input(testFile("input.qml")); + QVERIFY(input.open(QIODevice::ReadOnly)); + QByteArray contents = input.readAll(); + contents.replace("aaa", "bbb"); + serveFile(testFile("input.qml"), contents); + m_client->triggerLoad(testFileUrl(file)); + verifyProcessOutputContains("bbb #0000ff"); + + for (const QQmlProfilerEvent &event : clickEvents) + m_replay->sendEvent(mouseType, event); + + verifyProcessOutputContains("bbb #ff0000"); + + m_process->stop(); + QTRY_COMPARE(m_client->state(), QQmlDebugClient::NotConnected); + QVERIFY(m_serviceErrors.isEmpty()); +} + QTEST_MAIN(tst_QQmlPreview) #include "tst_qqmlpreview.moc" |
