From ca6762abde85fe3104ec4f064b85319474ba2deb Mon Sep 17 00:00:00 2001 From: Jocelyn Turcotte Date: Fri, 10 Jun 2016 15:06:03 +0200 Subject: Fix the IPC webChannelTransport not being available on reload MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The gin JavaScript binging gets destroyed on page reload after all references to it disappear from the previous document. Do like other gin wrapper and reinstall the transport binding on DidCreateDocumentElement, following how it's done by the MojoBindingsController. Task-number: QTBUG-53411 Change-Id: Ibcd9ef9dbedc5762d4f2210fd81f68e5b9127680 Reviewed-by: Michael BrĂ¼ning --- .../qwebenginescript/tst_qwebenginescript.cpp | 25 ++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'tests/auto/widgets/qwebenginescript') diff --git a/tests/auto/widgets/qwebenginescript/tst_qwebenginescript.cpp b/tests/auto/widgets/qwebenginescript/tst_qwebenginescript.cpp index ad10234f4..d5ecd8841 100644 --- a/tests/auto/widgets/qwebenginescript/tst_qwebenginescript.cpp +++ b/tests/auto/widgets/qwebenginescript/tst_qwebenginescript.cpp @@ -37,6 +37,7 @@ private Q_SLOTS: void scriptModifications(); void webChannel_data(); void webChannel(); + void noTransportWithoutWebChannel(); }; void tst_QWebEngineScript::domEditing() @@ -180,13 +181,17 @@ private: void tst_QWebEngineScript::webChannel_data() { QTest::addColumn("worldId"); - QTest::newRow("MainWorld") << static_cast(QWebEngineScript::MainWorld); - QTest::newRow("ApplicationWorld") << static_cast(QWebEngineScript::ApplicationWorld); + QTest::addColumn("reloadFirst"); + QTest::newRow("MainWorld") << static_cast(QWebEngineScript::MainWorld) << false; + QTest::newRow("ApplicationWorld") << static_cast(QWebEngineScript::ApplicationWorld) << false; + QTest::newRow("MainWorldWithReload") << static_cast(QWebEngineScript::MainWorld) << true; + QTest::newRow("ApplicationWorldWithReload") << static_cast(QWebEngineScript::ApplicationWorld) << true; } void tst_QWebEngineScript::webChannel() { QFETCH(int, worldId); + QFETCH(bool, reloadFirst); QWebEnginePage page; TestObject testObject; QScopedPointer channel(new QWebChannel(this)); @@ -205,6 +210,11 @@ void tst_QWebEngineScript::webChannel() page.scripts().insert(script); page.setHtml(QStringLiteral("")); waitForSignal(&page, SIGNAL(loadFinished(bool))); + if (reloadFirst) { + // Check that the transport is also reinstalled on navigation + page.triggerAction(QWebEnginePage::Reload); + waitForSignal(&page, SIGNAL(loadFinished(bool))); + } page.runJavaScript(QLatin1String( "new QWebChannel(qt.webChannelTransport," " function(channel) {" @@ -218,6 +228,17 @@ void tst_QWebEngineScript::webChannel() QCOMPARE(evaluateJavaScriptSync(&page, "qt.webChannelTransport"), QVariant(QVariant::Invalid)); } +void tst_QWebEngineScript::noTransportWithoutWebChannel() +{ + QWebEnginePage page; + page.setHtml(QStringLiteral("")); + + QCOMPARE(evaluateJavaScriptSync(&page, "qt.webChannelTransport"), QVariant(QVariant::Invalid)); + page.triggerAction(QWebEnginePage::Reload); + waitForSignal(&page, SIGNAL(loadFinished(bool))); + QCOMPARE(evaluateJavaScriptSync(&page, "qt.webChannelTransport"), QVariant(QVariant::Invalid)); +} + QTEST_MAIN(tst_QWebEngineScript) #include "tst_qwebenginescript.moc" -- cgit v1.2.3