diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2019-04-09 13:50:17 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2019-04-09 13:50:17 +0200 |
commit | c9a64fda178c32ac924977ac93bf83d7e47767fe (patch) | |
tree | beaf8671ccbce36b3d4018ce57fe9de29d40d87f /tests/auto/widgets/qwebenginescript/tst_qwebenginescript.cpp | |
parent | 10611866af8736a397371a38d6b5486ee8d28c62 (diff) | |
parent | 44303861fd116b3a279d26300147e89a0bf8121c (diff) | |
download | qtwebengine-c9a64fda178c32ac924977ac93bf83d7e47767fe.tar.gz |
Merge branch '5.12' into 5.13
Conflicts:
src/3rdparty
src/core/renderer/user_resource_controller.cpp
src/core/web_contents_adapter.cpp
src/webengine/doc/src/qtwebengine-overview.qdoc
Change-Id: I46be9d33b3b65d61dfa099ee72a3509afb9bd6a4
Diffstat (limited to 'tests/auto/widgets/qwebenginescript/tst_qwebenginescript.cpp')
-rw-r--r-- | tests/auto/widgets/qwebenginescript/tst_qwebenginescript.cpp | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/tests/auto/widgets/qwebenginescript/tst_qwebenginescript.cpp b/tests/auto/widgets/qwebenginescript/tst_qwebenginescript.cpp index 0fe0ec6cf..be9e59b8c 100644 --- a/tests/auto/widgets/qwebenginescript/tst_qwebenginescript.cpp +++ b/tests/auto/widgets/qwebenginescript/tst_qwebenginescript.cpp @@ -23,6 +23,7 @@ #include <qwebengineprofile.h> #include <qwebenginescript.h> #include <qwebenginescriptcollection.h> +#include <qwebenginesettings.h> #include <qwebengineview.h> #include "../util.h" #if QT_CONFIG(webengine_webchannel) @@ -37,6 +38,8 @@ private Q_SLOTS: void loadEvents(); void scriptWorld_data(); void scriptWorld(); + void scriptDisabled(); + void viewSource(); void scriptModifications(); #if QT_CONFIG(webengine_webchannel) void webChannel_data(); @@ -218,6 +221,50 @@ void tst_QWebEngineScript::scriptWorld() QCOMPARE(evaluateJavaScriptSyncInWorld(&page, "typeof(userScriptTest) != \"undefined\" && userScriptTest == 1;", worldId), QVariant::fromValue(true)); } +// Based on QTBUG-74304 +void tst_QWebEngineScript::scriptDisabled() +{ + QWebEnginePage page; + page.settings()->setAttribute(QWebEngineSettings::JavascriptEnabled, false); + QWebEngineScript script; + script.setInjectionPoint(QWebEngineScript::DocumentCreation); + script.setWorldId(QWebEngineScript::MainWorld); + script.setSourceCode("var foo = 42"); + page.scripts().insert(script); + page.load(QUrl("about:blank")); + QSignalSpy spy(&page, &QWebEnginePage::loadFinished); + QTRY_COMPARE(spy.count(), 1); + QCOMPARE(spy.takeFirst().value(0).toBool(), true); + // MainWorld scripts are disabled by the setting... + QCOMPARE(evaluateJavaScriptSyncInWorld(&page, "foo", QWebEngineScript::MainWorld), QVariant()); + QCOMPARE(evaluateJavaScriptSyncInWorld(&page, "foo", QWebEngineScript::ApplicationWorld), QVariant()); + script.setWorldId(QWebEngineScript::ApplicationWorld); + page.scripts().clear(); + page.scripts().insert(script); + page.load(QUrl("about:blank")); + QTRY_COMPARE(spy.count(), 1); + QCOMPARE(spy.takeFirst().value(0).toBool(), true); + // ...but ApplicationWorld scripts should still work + QCOMPARE(evaluateJavaScriptSyncInWorld(&page, "foo", QWebEngineScript::MainWorld), QVariant()); + QCOMPARE(evaluateJavaScriptSyncInWorld(&page, "foo", QWebEngineScript::ApplicationWorld), QVariant(42)); +} + +// Based on QTBUG-66011 +void tst_QWebEngineScript::viewSource() +{ + QWebEnginePage page; + QWebEngineScript script; + script.setInjectionPoint(QWebEngineScript::DocumentCreation); + script.setWorldId(QWebEngineScript::MainWorld); + script.setSourceCode("var foo = 42"); + page.scripts().insert(script); + page.load(QUrl("view-source:about:blank")); + QSignalSpy spy(&page, &QWebEnginePage::loadFinished); + QTRY_COMPARE(spy.count(), 1); + QCOMPARE(spy.takeFirst().value(0).toBool(), true); + QCOMPARE(evaluateJavaScriptSync(&page, "foo"), QVariant(42)); +} + void tst_QWebEngineScript::scriptModifications() { QWebEnginePage page; |