diff options
author | Kirill Burtsev <kirill.burtsev@qt.io> | 2021-09-16 22:08:22 +0200 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2022-02-10 16:54:50 +0000 |
commit | 9d350003fe1c3b5b0b1f839a66ddfb4650abc1ec (patch) | |
tree | f709c59f27de5b06731df9c427ced6bdc320af63 | |
parent | cfb1051fb3055f1786bec84cc21d0b5d7076d05a (diff) |
Fix crash on WebEngine(View|Profile).userScripts.collection get
To create a javascript list on 'collection' method qml engine is needed
for a qml scope, but it's only available for objects, which are created
by the QML Engine itself. The only object in hierarchy of classes is an
actual WebEngineView, so get it from there on collection init.
Also implement delayed initialization of scripts collection for the
usage of default profile through WebEngine singleton, and for the reason
that it's not really needed until really asked by user code.
Fixes: QTBUG-96597
Change-Id: I61e76652a5d0fd5609070fd541816503908f2dc8
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
(cherry picked from commit f5fbc34fc16fc9c6e7f7e8bbbf60f5b343b9466d)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r-- | src/core/api/qwebenginescriptcollection.h | 1 | ||||
-rw-r--r-- | src/webenginequick/CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/webenginequick/api/qquickwebengineprofile.cpp | 30 | ||||
-rw-r--r-- | src/webenginequick/api/qquickwebengineprofile.h | 1 | ||||
-rw-r--r-- | src/webenginequick/api/qquickwebengineprofile_p.h | 2 | ||||
-rw-r--r-- | src/webenginequick/api/qquickwebenginescriptcollection.cpp | 36 | ||||
-rw-r--r-- | src/webenginequick/api/qquickwebenginescriptcollection_p.h | 9 | ||||
-rw-r--r-- | src/webenginequick/api/qquickwebenginescriptcollection_p_p.h | 74 | ||||
-rw-r--r-- | src/webenginequick/api/qquickwebenginesingleton.cpp | 11 | ||||
-rw-r--r-- | src/webenginequick/api/qquickwebengineview.cpp | 34 | ||||
-rw-r--r-- | src/webenginequick/api/qquickwebengineview_p_p.h | 1 | ||||
-rw-r--r-- | tests/auto/quick/qmltests/data/tst_userScripts.qml | 42 |
12 files changed, 216 insertions, 27 deletions
diff --git a/src/core/api/qwebenginescriptcollection.h b/src/core/api/qwebenginescriptcollection.h index 7bc9005cb..35a35e266 100644 --- a/src/core/api/qwebenginescriptcollection.h +++ b/src/core/api/qwebenginescriptcollection.h @@ -70,6 +70,7 @@ private: friend class QWebEngineProfilePrivate; friend class QQuickWebEngineProfilePrivate; friend class QQuickWebEngineViewPrivate; + friend class QQuickWebEngineScriptCollectionPrivate; QWebEngineScriptCollection(QWebEngineScriptCollectionPrivate *); QScopedPointer<QWebEngineScriptCollectionPrivate> d; diff --git a/src/webenginequick/CMakeLists.txt b/src/webenginequick/CMakeLists.txt index 7cadf602c..9182a4946 100644 --- a/src/webenginequick/CMakeLists.txt +++ b/src/webenginequick/CMakeLists.txt @@ -17,7 +17,7 @@ qt_internal_add_qml_module(WebEngineQuick api/qquickwebenginefaviconprovider_p_p.h api/qquickwebenginenewwindowrequest.cpp api/qquickwebenginenewwindowrequest_p.h api/qquickwebengineprofile.cpp api/qquickwebengineprofile.h api/qquickwebengineprofile_p.h - api/qquickwebenginescriptcollection.cpp api/qquickwebenginescriptcollection_p.h + api/qquickwebenginescriptcollection.cpp api/qquickwebenginescriptcollection_p.h api/qquickwebenginescriptcollection_p_p.h api/qquickwebenginesettings.cpp api/qquickwebenginesettings_p.h api/qquickwebenginesingleton.cpp api/qquickwebenginesingleton_p.h api/qquickwebenginetouchhandleprovider.cpp diff --git a/src/webenginequick/api/qquickwebengineprofile.cpp b/src/webenginequick/api/qquickwebengineprofile.cpp index 6944de95f..f052d201c 100644 --- a/src/webenginequick/api/qquickwebengineprofile.cpp +++ b/src/webenginequick/api/qquickwebengineprofile.cpp @@ -42,6 +42,7 @@ #include "qquickwebenginedownloadrequest_p.h" #include "qquickwebenginesettings_p.h" #include "qquickwebenginescriptcollection_p.h" +#include "qquickwebenginescriptcollection_p_p.h" #include "qquickwebengineview_p_p.h" #include "profile_adapter.h" @@ -56,6 +57,7 @@ #include <QtCore/qdir.h> #include <QtCore/qfileinfo.h> +#include <QtQml/qqmlcontext.h> #include <QtQml/qqmlengine.h> using QtWebEngineCore::ProfileAdapter; @@ -161,8 +163,6 @@ QT_BEGIN_NAMESPACE QQuickWebEngineProfilePrivate::QQuickWebEngineProfilePrivate(ProfileAdapter *profileAdapter) : m_settings(new QQuickWebEngineSettings()) , m_profileAdapter(profileAdapter) - , m_scriptCollection(new QQuickWebEngineScriptCollection(new QWebEngineScriptCollection( - new QWebEngineScriptCollectionPrivate(profileAdapter->userResourceController())))) { profileAdapter->addClient(this); // Fullscreen API was implemented before the supported setting, so we must @@ -305,6 +305,21 @@ void QQuickWebEngineProfilePrivate::showNotification(QSharedPointer<QtWebEngineC Q_EMIT q->presentNotification(notification); } +QQuickWebEngineScriptCollection *QQuickWebEngineProfilePrivate::getUserScripts() +{ + Q_Q(QQuickWebEngineProfile); + if (!m_scriptCollection) + m_scriptCollection.reset( + new QQuickWebEngineScriptCollection( + new QQuickWebEngineScriptCollectionPrivate( + new QWebEngineScriptCollectionPrivate( + m_profileAdapter->userResourceController())))); + + if (!m_scriptCollection->qmlEngine()) + m_scriptCollection->setQmlEngine(qmlEngine(q)); + + return m_scriptCollection.data(); +} /*! \qmltype WebEngineProfile \instantiates QQuickWebEngineProfile @@ -947,8 +962,7 @@ QQuickWebEngineSettings *QQuickWebEngineProfile::settings() const QQuickWebEngineScriptCollection *QQuickWebEngineProfile::userScripts() const { - const Q_D(QQuickWebEngineProfile); - return d->m_scriptCollection.data(); + return d_ptr->getUserScripts(); } /*! @@ -966,6 +980,14 @@ QWebEngineClientCertificateStore *QQuickWebEngineProfile::clientCertificateStore #endif } +void QQuickWebEngineProfile::ensureQmlContext(const QObject *object) +{ + if (!qmlContext(this)) { + auto engine = qmlEngine(object); + QQmlEngine::setContextForObject(this, new QQmlContext(engine, engine)); + } +} + QT_END_NAMESPACE #include "moc_qquickwebengineprofile.cpp" diff --git a/src/webenginequick/api/qquickwebengineprofile.h b/src/webenginequick/api/qquickwebengineprofile.h index e594b5982..029238a0a 100644 --- a/src/webenginequick/api/qquickwebengineprofile.h +++ b/src/webenginequick/api/qquickwebengineprofile.h @@ -170,6 +170,7 @@ private: Q_DECLARE_PRIVATE(QQuickWebEngineProfile) QQuickWebEngineProfile(QQuickWebEngineProfilePrivate *, QObject *parent = nullptr); QQuickWebEngineSettings *settings() const; + void ensureQmlContext(const QObject *object); friend class FaviconImageResponseRunnable; friend class QQuickWebEngineSingleton; diff --git a/src/webenginequick/api/qquickwebengineprofile_p.h b/src/webenginequick/api/qquickwebengineprofile_p.h index 5ff3c6913..4e3ba7ff6 100644 --- a/src/webenginequick/api/qquickwebengineprofile_p.h +++ b/src/webenginequick/api/qquickwebengineprofile_p.h @@ -95,7 +95,9 @@ private: QScopedPointer<QQuickWebEngineSettings> m_settings; QPointer<QtWebEngineCore::ProfileAdapter> m_profileAdapter; QMap<quint32, QPointer<QQuickWebEngineDownloadRequest> > m_ongoingDownloads; + QScopedPointer<QQuickWebEngineScriptCollection> m_scriptCollection; + QQuickWebEngineScriptCollection *getUserScripts(); }; QT_END_NAMESPACE diff --git a/src/webenginequick/api/qquickwebenginescriptcollection.cpp b/src/webenginequick/api/qquickwebenginescriptcollection.cpp index cc1cfb2fa..9a12c6f5c 100644 --- a/src/webenginequick/api/qquickwebenginescriptcollection.cpp +++ b/src/webenginequick/api/qquickwebenginescriptcollection.cpp @@ -38,6 +38,7 @@ ****************************************************************************/ #include "qquickwebenginescriptcollection_p.h" +#include "qquickwebenginescriptcollection_p_p.h" #include "qwebenginescriptcollection.h" #include <QtWebEngineCore/private/qwebenginescriptcollection_p.h> #include <QtQml/qqmlinfo.h> @@ -79,9 +80,18 @@ QWebEngineScript parseScript(const QJSValue &value, bool *ok) return s; } -QQuickWebEngineScriptCollection::QQuickWebEngineScriptCollection( - QWebEngineScriptCollection *collection) - : d(collection) +QQuickWebEngineScriptCollectionPrivate::QQuickWebEngineScriptCollectionPrivate(QWebEngineScriptCollectionPrivate *p) + : QWebEngineScriptCollection(p) +{ + +} + +QQuickWebEngineScriptCollectionPrivate::~QQuickWebEngineScriptCollectionPrivate() +{ +} + +QQuickWebEngineScriptCollection::QQuickWebEngineScriptCollection(QQuickWebEngineScriptCollectionPrivate *p) + : d(p) { } @@ -119,10 +129,13 @@ void QQuickWebEngineScriptCollection::clear() QJSValue QQuickWebEngineScriptCollection::collection() const { + if (!d->m_qmlEngine) { + qmlWarning(this) << "Scripts collection doesn't have QML engine set! Undefined value is returned."; + return QJSValue(); + } + const QList<QWebEngineScript> &list = d->toList(); - QQmlContext *context = QQmlEngine::contextForObject(this); - QQmlEngine *engine = context->engine(); - QV4::ExecutionEngine *v4 = QQmlEnginePrivate::getV4Engine(engine); + QV4::ExecutionEngine *v4 = QQmlEnginePrivate::getV4Engine(d->m_qmlEngine); QV4::Scope scope(v4); QV4::Scoped<QV4::ArrayObject> scriptArray(scope, v4->newArrayObject(list.length())); int i = 0; @@ -155,3 +168,14 @@ void QQuickWebEngineScriptCollection::setCollection(const QJSValue &scripts) Q_EMIT collectionChanged(); } } + +QQmlEngine* QQuickWebEngineScriptCollection::qmlEngine() +{ + return d->m_qmlEngine; +} + +void QQuickWebEngineScriptCollection::setQmlEngine(QQmlEngine *engine) +{ + Q_ASSERT(engine); + d->m_qmlEngine = engine; +} diff --git a/src/webenginequick/api/qquickwebenginescriptcollection_p.h b/src/webenginequick/api/qquickwebenginescriptcollection_p.h index 8c5682706..242118215 100644 --- a/src/webenginequick/api/qquickwebenginescriptcollection_p.h +++ b/src/webenginequick/api/qquickwebenginescriptcollection_p.h @@ -59,7 +59,8 @@ #include <QtWebEngineQuick/private/qtwebenginequickglobal_p.h> QT_BEGIN_NAMESPACE -class QWebEngineScriptCollection; +class QQmlEngine; +class QQuickWebEngineScriptCollectionPrivate; class Q_WEBENGINEQUICK_PRIVATE_EXPORT QQuickWebEngineScriptCollection : public QObject { @@ -83,10 +84,12 @@ Q_SIGNALS: private: Q_DISABLE_COPY(QQuickWebEngineScriptCollection) - QQuickWebEngineScriptCollection(QWebEngineScriptCollection *d); - QScopedPointer<QWebEngineScriptCollection> d; + QQuickWebEngineScriptCollection(QQuickWebEngineScriptCollectionPrivate *d); + QScopedPointer<QQuickWebEngineScriptCollectionPrivate> d; friend class QQuickWebEngineProfilePrivate; friend class QQuickWebEngineViewPrivate; + QQmlEngine* qmlEngine(); + void setQmlEngine(QQmlEngine *engine); }; QT_END_NAMESPACE diff --git a/src/webenginequick/api/qquickwebenginescriptcollection_p_p.h b/src/webenginequick/api/qquickwebenginescriptcollection_p_p.h new file mode 100644 index 000000000..2c1564557 --- /dev/null +++ b/src/webenginequick/api/qquickwebenginescriptcollection_p_p.h @@ -0,0 +1,74 @@ +/**************************************************************************** +** +** Copyright (C) 2022 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtWebEngine module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** 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 Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** 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-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QQUICKWEBENGINESCRIPTCOLLECTIONPRIVATE_H +#define QQUICKWEBENGINESCRIPTCOLLECTIONPRIVATE_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include <QtWebEngineCore/qwebenginescriptcollection.h> + +#include <QPointer> + +QT_BEGIN_NAMESPACE + +class QQmlEngine; + +class QQuickWebEngineScriptCollectionPrivate : public QWebEngineScriptCollection +{ +public: + QQuickWebEngineScriptCollectionPrivate(QWebEngineScriptCollectionPrivate *d); + ~QQuickWebEngineScriptCollectionPrivate(); + + Q_DISABLE_COPY(QQuickWebEngineScriptCollectionPrivate) + QPointer<QQmlEngine> m_qmlEngine; +}; + +QT_END_NAMESPACE + +#endif diff --git a/src/webenginequick/api/qquickwebenginesingleton.cpp b/src/webenginequick/api/qquickwebenginesingleton.cpp index 40ae87a68..3d15a3a2c 100644 --- a/src/webenginequick/api/qquickwebenginesingleton.cpp +++ b/src/webenginequick/api/qquickwebenginesingleton.cpp @@ -41,6 +41,9 @@ #include "qquickwebenginesettings_p.h" #include "qquickwebenginesingleton_p.h" +#include <QtQml/qqmlcontext.h> +#include <QtQml/qqmlengine.h> + QT_BEGIN_NAMESPACE /*! @@ -87,7 +90,13 @@ QQuickWebEngineSettings *QQuickWebEngineSingleton::settings() const */ QQuickWebEngineProfile *QQuickWebEngineSingleton::defaultProfile() const { - return QQuickWebEngineProfile::defaultProfile(); + auto profile = QQuickWebEngineProfile::defaultProfile(); + + // MEMO first ever call to default profile will create one without context + // it needs something to get qml engine from (WebEngine singleton is created in qml land) + profile->ensureQmlContext(this); + + return profile; } QWebEngineScript QQuickWebEngineSingleton::script() const diff --git a/src/webenginequick/api/qquickwebengineview.cpp b/src/webenginequick/api/qquickwebengineview.cpp index 7e2240698..1a22720ff 100644 --- a/src/webenginequick/api/qquickwebengineview.cpp +++ b/src/webenginequick/api/qquickwebengineview.cpp @@ -46,6 +46,7 @@ #include "qquickwebengineprofile.h" #include "qquickwebengineprofile_p.h" #include "qquickwebenginescriptcollection_p.h" +#include "qquickwebenginescriptcollection_p_p.h" #include "qquickwebenginesettings_p.h" #include "qquickwebenginetouchhandleprovider_p_p.h" #include "qquickwebengineview_p.h" @@ -190,14 +191,18 @@ void QQuickWebEngineViewPrivate::initializeProfile() if (!m_profileInitialized) { Q_ASSERT(!adapter->isInitialized()); m_profileInitialized = true; - if (!m_profile) + + if (!m_profile) { m_profile = QQuickWebEngineProfile::defaultProfile(); + + // MEMO first ever call to default profile will create one without context + // it needs something to get qml engine from (and view is created in qml land) + m_profile->ensureQmlContext(q_ptr); + } + m_profile->d_ptr->addWebContentsAdapterClient(this); m_settings.reset(new QQuickWebEngineSettings(m_profile->settings())); adapter->setClient(this); - m_scriptCollection.reset(new QQuickWebEngineScriptCollection( - new QWebEngineScriptCollection(new QWebEngineScriptCollectionPrivate( - profileAdapter()->userResourceController(), adapter)))); } } @@ -862,7 +867,8 @@ void QQuickWebEngineViewPrivate::initializationFinished() if (devToolsView && devToolsView->d_ptr->adapter) adapter->openDevToolsFrontend(devToolsView->d_ptr->adapter); - m_scriptCollection->d->d->initializationFinished(adapter); + if (m_scriptCollection) + m_scriptCollection->d->d->initializationFinished(adapter); if (q->window()) adapter->setVisible(q->isVisible()); @@ -1012,6 +1018,22 @@ void QQuickWebEngineViewPrivate::updateEditActions() updateAction(QQuickWebEngineView::Unselect); } +QQuickWebEngineScriptCollection *QQuickWebEngineViewPrivate::getUserScripts() +{ + Q_Q(QQuickWebEngineView); + if (!m_scriptCollection) + m_scriptCollection.reset( + new QQuickWebEngineScriptCollection( + new QQuickWebEngineScriptCollectionPrivate( + new QWebEngineScriptCollectionPrivate( + profileAdapter()->userResourceController(), adapter)))); + + if (!m_scriptCollection->qmlEngine()) + m_scriptCollection->setQmlEngine(qmlEngine(q)); + + return m_scriptCollection.data(); +} + QUrl QQuickWebEngineView::url() const { Q_D(const QQuickWebEngineView); @@ -1133,7 +1155,7 @@ QQuickWebEngineSettings *QQuickWebEngineView::settings() QQuickWebEngineScriptCollection *QQuickWebEngineView::userScripts() { Q_D(QQuickWebEngineView); - return d->m_scriptCollection.data(); + return d->getUserScripts(); } void QQuickWebEngineViewPrivate::updateAdapter() diff --git a/src/webenginequick/api/qquickwebengineview_p_p.h b/src/webenginequick/api/qquickwebengineview_p_p.h index 0f6eceb56..a10c12481 100644 --- a/src/webenginequick/api/qquickwebengineview_p_p.h +++ b/src/webenginequick/api/qquickwebengineview_p_p.h @@ -199,6 +199,7 @@ public: QtWebEngineCore::RenderWidgetHostViewQtDelegateQuick *widget = nullptr; bool profileInitialized() const; + QQuickWebEngineScriptCollection *getUserScripts(); private: QScopedPointer<QtWebEngineCore::UIDelegatesManager> m_uIDelegatesManager; diff --git a/tests/auto/quick/qmltests/data/tst_userScripts.qml b/tests/auto/quick/qmltests/data/tst_userScripts.qml index 0f1042f80..f885368ec 100644 --- a/tests/auto/quick/qmltests/data/tst_userScripts.qml +++ b/tests/auto/quick/qmltests/data/tst_userScripts.qml @@ -60,6 +60,8 @@ Item { return script } + WebEngineProfile { id: testProfile } + TestWebEngineView { id: webEngineView width: 400 @@ -89,13 +91,28 @@ Item { } TestCase { - name: "WebEngineViewUserScripts" - + name: "UserScripts" - function init() { + function cleanup() { webEngineView.url = ""; webEngineView.userScripts.collection = []; + compare(webEngineView.userScripts.collection.length, 0) webEngineView.profile.userScripts.collection = []; + compare(webEngineView.profile.userScripts.collection.length, 0) + } + + function test_profileScripts() { + // assusme it is the same type as in View + let t1 = String(testProfile.userScripts), t2 = String(webEngineView.userScripts) + compare(t1.substr(0, t1.indexOf('(')), t2.substr(0, t2.indexOf('('))) + + // ... and just test basic things like access + compare(testProfile.userScripts.collection, []) + let script = changeDocumentTitleScript() + testProfile.userScripts.collection = [ script ] + + compare(testProfile.userScripts.collection.length, 1) + compare(testProfile.userScripts.collection[0].name, script.name) } function test_oneScript() { @@ -103,8 +120,10 @@ Item { webEngineView.waitForLoadSucceeded(); tryCompare(webEngineView, "title", "Test page 1"); - webEngineView.userScripts.collection = [ changeDocumentTitleScript() ] - + let script = changeDocumentTitleScript() + webEngineView.userScripts.collection = [ script ] + compare(webEngineView.userScripts.collection.length, 1) + compare(webEngineView.userScripts.collection[0].name, script.name) compare(webEngineView.title, "Test page 1"); webEngineView.reload(); @@ -116,6 +135,7 @@ Item { tryCompare(webEngineView, "title", "New title"); webEngineView.userScripts.collection = []; + compare(webEngineView.userScripts.collection.length, 0) compare(webEngineView.title, "New title"); webEngineView.reload(); @@ -131,6 +151,7 @@ Item { var script2 = appendDocumentTitleScript(); script2.injectionPoint = WebEngineScript.Deferred; webEngineView.userScripts.collection = [ script1, script2 ]; + compare(webEngineView.userScripts.collection.length, 2) // Make sure the scripts are loaded in order. webEngineView.reload(); @@ -140,12 +161,14 @@ Item { script2.injectionPoint = WebEngineScript.DocumentReady script1.injectionPoint = WebEngineScript.Deferred webEngineView.userScripts.collection = [ script1, script2 ]; + compare(webEngineView.userScripts.collection.length, 2) webEngineView.reload(); webEngineView.waitForLoadSucceeded(); tryCompare(webEngineView, "title", "New title"); // Make sure we can remove scripts from the preload list. webEngineView.userScripts.collection = [ script2 ]; + compare(webEngineView.userScripts.collection.length, 1) webEngineView.reload(); webEngineView.waitForLoadSucceeded(); tryCompare(webEngineView, "title", "Test page 1 with appendix"); @@ -169,6 +192,7 @@ Item { function test_bigScript() { webEngineView.userScripts.collection = [ bigUserScript() ]; + compare(webEngineView.userScripts.collection.length, 1) webEngineView.url = Qt.resolvedUrl("test1.html"); webEngineView.waitForLoadSucceeded(); tryCompare(webEngineView , "title", "Big user script changed title"); @@ -180,6 +204,8 @@ Item { compare(script.injectionPoint, WebEngineScript.DocumentReady); webEngineView.userScripts.collection = [ script ]; + compare(webEngineView.userScripts.collection.length, 1) + compare(webEngineView.userScripts.collection[0].name, script.name) // @include *data/test*.html webEngineView.url = Qt.resolvedUrl("test1.html"); @@ -208,6 +234,7 @@ Item { compare(script.injectionPoint, WebEngineScript.DocumentReady); webEngineView.userScripts.collection = [ script ]; + compare(webEngineView.userScripts.collection.length, 1) // @match some:junk webEngineView.url = Qt.resolvedUrl("test2.html"); @@ -216,7 +243,10 @@ Item { } function test_profileWideScript() { - webEngineView.profile.userScripts.collection = [ changeDocumentTitleScript() ]; + let script = changeDocumentTitleScript() + webEngineView.profile.userScripts.collection = [ script ]; + compare(webEngineView.profile.userScripts.collection.length, 1) + compare(webEngineView.profile.userScripts.collection[0].name, script.name) webEngineView.url = Qt.resolvedUrl("test1.html"); webEngineView.waitForLoadSucceeded(); |