diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2023-04-24 17:33:17 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2023-04-30 17:46:36 +0000 |
commit | 17c64fd5d2778df4a52849e8942104d4d9555a1e (patch) | |
tree | 0ef70dc889f3e6b34eb087101e63f71ab399d868 /tests/auto | |
parent | 6b3e7f2baa17a5bff7051949f743f2ec6926ec06 (diff) |
Fix user script management when subframes are present
Only the main frames should administer scripts associated with it.
Pick-to: 6.5
Fixes: QTBUG-113109
Change-Id: Ibda66f55ef99da632134a9de1425797262faba9b
Reviewed-by: Michael BrĂ¼ning <michael.bruning@qt.io>
Reviewed-by: Martin Negyokru <negyokru@inf.u-szeged.hu>
Diffstat (limited to 'tests/auto')
-rw-r--r-- | tests/auto/widgets/qwebenginescript/tst_qwebenginescript.cpp | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/tests/auto/widgets/qwebenginescript/tst_qwebenginescript.cpp b/tests/auto/widgets/qwebenginescript/tst_qwebenginescript.cpp index ed12fdba0..9ba13589f 100644 --- a/tests/auto/widgets/qwebenginescript/tst_qwebenginescript.cpp +++ b/tests/auto/widgets/qwebenginescript/tst_qwebenginescript.cpp @@ -76,6 +76,7 @@ private Q_SLOTS: void scriptsInNestedIframes(); void matchQrcUrl(); void injectionOrder(); + void reloadWithSubframes(); }; void tst_QWebEngineScript::domEditing() @@ -694,6 +695,38 @@ void tst_QWebEngineScript::injectionOrder() QTRY_COMPARE(page.log, expected); } +void tst_QWebEngineScript::reloadWithSubframes() +{ + class Page : public QWebEnginePage + { + public: + Page() : QWebEnginePage() {} + QVector<QString> log; + + protected: + void javaScriptConsoleMessage(JavaScriptConsoleMessageLevel, const QString &message, int, + const QString &) override + { + log.append(message); + } + } page; + + QWebEngineScript s; + s.setInjectionPoint(QWebEngineScript::DocumentCreation); + s.setSourceCode(QStringLiteral("console.log('Hello');")); + page.scripts().insert(s); + + page.setHtml(QStringLiteral("<body>" + " <h1>Test scripts working on reload </h1>" + " <iframe src='about://blank'>" + " </iframe>" + "</body>")); + QTRY_COMPARE(page.log.size(), 1); + + page.triggerAction(QWebEnginePage::Reload); + QTRY_COMPARE(page.log.size(), 2); +} + QTEST_MAIN(tst_QWebEngineScript) #include "tst_qwebenginescript.moc" |