summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorSzabolcs David <davidsz@inf.u-szeged.hu>2021-09-20 09:29:30 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2021-09-27 13:02:33 +0000
commite5b7db68e30251ee2044607d939f54bd5628a68c (patch)
tree7f201bb3534fa4b05f3c7d28ea661dfcd11d9dde /tests
parenta4acb16421338cd0e38de794e943e0dcbe283538 (diff)
Fix WebChannel when JavaScript is disabled
WebChannel was not working in ApplicationWorld with JavaScript disabled in MainWorld, because WebChannelIPCTransport::DidClearWindowObject() is called only when the window object was cleared in the main world. Moving the WebChannelTransport installation logic to DidCreateScriptContext() works in other worlds, so fixes the problem. Task-number: QTBUG-88875 Change-Id: Ia75613b66a1e049f617f0664684b153b6875e9de Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io> (cherry picked from commit 70abc0b2eebc777309d372203df5ca1e785402d8) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/widgets/qwebenginescript/tst_qwebenginescript.cpp31
1 files changed, 31 insertions, 0 deletions
diff --git a/tests/auto/widgets/qwebenginescript/tst_qwebenginescript.cpp b/tests/auto/widgets/qwebenginescript/tst_qwebenginescript.cpp
index ca2f0cab9..5df9f035f 100644
--- a/tests/auto/widgets/qwebenginescript/tst_qwebenginescript.cpp
+++ b/tests/auto/widgets/qwebenginescript/tst_qwebenginescript.cpp
@@ -70,6 +70,7 @@ private Q_SLOTS:
void webChannelWithExistingQtObject();
void navigation();
void webChannelWithBadString();
+ void webChannelWithJavaScriptDisabled();
#endif
void noTransportWithoutWebChannel();
void scriptsInNestedIframes();
@@ -592,6 +593,36 @@ void tst_QWebEngineScript::webChannelWithBadString()
QChar data(0xd800);
QCOMPARE(host.text(), data);
}
+
+void tst_QWebEngineScript::webChannelWithJavaScriptDisabled()
+{
+ QWebEnginePage page;
+ QSignalSpy spyFinished(&page, &QWebEnginePage::loadFinished);
+ // JavaScript disabled in main world
+ page.settings()->setAttribute(QWebEngineSettings::JavascriptEnabled, false);
+
+ TestObject testObject;
+ QScopedPointer<QWebChannel> channel(new QWebChannel(this));
+ channel->registerObject(QStringLiteral("object"), &testObject);
+ page.setWebChannel(channel.data(), QWebEngineScript::ApplicationWorld);
+
+ QWebEngineScript script = webChannelScript();
+ script.setWorldId(QWebEngineScript::ApplicationWorld);
+ page.scripts().insert(script);
+
+ page.setHtml(QStringLiteral("<html><body></body></html>"));
+ QVERIFY(spyFinished.wait());
+
+ QSignalSpy spyTextChanged(&testObject, &TestObject::textChanged);
+ page.runJavaScript(QLatin1String(
+ "new QWebChannel(qt.webChannelTransport,"
+ " function(channel) {"
+ " channel.objects.object.text = 'test';"
+ " }"
+ ");"), QWebEngineScript::ApplicationWorld);
+ QVERIFY(spyTextChanged.wait());
+ QCOMPARE(testObject.text(), QStringLiteral("test"));
+}
#endif
void tst_QWebEngineScript::matchQrcUrl()