diff options
Diffstat (limited to 'tests/auto/widgets/qwebenginescript/tst_qwebenginescript.cpp')
-rw-r--r-- | tests/auto/widgets/qwebenginescript/tst_qwebenginescript.cpp | 34 |
1 files changed, 25 insertions, 9 deletions
diff --git a/tests/auto/widgets/qwebenginescript/tst_qwebenginescript.cpp b/tests/auto/widgets/qwebenginescript/tst_qwebenginescript.cpp index 23d31a478..0fe0ec6cf 100644 --- a/tests/auto/widgets/qwebenginescript/tst_qwebenginescript.cpp +++ b/tests/auto/widgets/qwebenginescript/tst_qwebenginescript.cpp @@ -18,14 +18,16 @@ */ #include <QtTest/QtTest> - +#include <QtWebEngineCore/qtwebenginecore-config.h> #include <qwebenginepage.h> #include <qwebengineprofile.h> #include <qwebenginescript.h> #include <qwebenginescriptcollection.h> #include <qwebengineview.h> #include "../util.h" +#if QT_CONFIG(webengine_webchannel) #include <QWebChannel> +#endif class tst_QWebEngineScript: public QObject { Q_OBJECT @@ -33,16 +35,19 @@ class tst_QWebEngineScript: public QObject { private Q_SLOTS: void domEditing(); void loadEvents(); + void scriptWorld_data(); void scriptWorld(); void scriptModifications(); +#if QT_CONFIG(webengine_webchannel) void webChannel_data(); void webChannel(); - void noTransportWithoutWebChannel(); - void scriptsInNestedIframes(); void webChannelResettingAndUnsetting(); void webChannelWithExistingQtObject(); void navigation(); void webChannelWithBadString(); +#endif + void noTransportWithoutWebChannel(); + void scriptsInNestedIframes(); }; void tst_QWebEngineScript::domEditing() @@ -181,8 +186,18 @@ void tst_QWebEngineScript::loadEvents() QCOMPARE(profile.pages.back().eval("window.log", QWebEngineScript::ApplicationWorld).toStringList(), expected); } +void tst_QWebEngineScript::scriptWorld_data() +{ + QTest::addColumn<int>("worldId"); + + QTest::newRow("ApplicationWorld") << static_cast<int>(QWebEngineScript::ApplicationWorld); + QTest::newRow("UserWorld") << static_cast<int>(QWebEngineScript::UserWorld); + QTest::newRow("150") << 150; +} + void tst_QWebEngineScript::scriptWorld() { + QFETCH(int, worldId); QWebEnginePage page; QWebEngineScript script; script.setInjectionPoint(QWebEngineScript::DocumentCreation); @@ -193,14 +208,14 @@ void tst_QWebEngineScript::scriptWorld() QSignalSpy spyFinished(&page, &QWebEnginePage::loadFinished); QVERIFY(spyFinished.wait()); QCOMPARE(evaluateJavaScriptSync(&page, "typeof(userScriptTest) != \"undefined\" && userScriptTest == 1;"), QVariant::fromValue(true)); - QCOMPARE(evaluateJavaScriptSyncInWorld(&page, "typeof(userScriptTest) == \"undefined\"", QWebEngineScript::ApplicationWorld), QVariant::fromValue(true)); - script.setWorldId(QWebEngineScript::ApplicationWorld); + QCOMPARE(evaluateJavaScriptSyncInWorld(&page, "typeof(userScriptTest) == \"undefined\"", worldId), QVariant::fromValue(true)); + script.setWorldId(worldId); page.scripts().clear(); page.scripts().insert(script); page.load(QUrl("about:blank")); QVERIFY(spyFinished.wait()); QCOMPARE(evaluateJavaScriptSync(&page, "typeof(userScriptTest) == \"undefined\""), QVariant::fromValue(true)); - QCOMPARE(evaluateJavaScriptSyncInWorld(&page, "typeof(userScriptTest) != \"undefined\" && userScriptTest == 1;", QWebEngineScript::ApplicationWorld), QVariant::fromValue(true)); + QCOMPARE(evaluateJavaScriptSyncInWorld(&page, "typeof(userScriptTest) != \"undefined\" && userScriptTest == 1;", worldId), QVariant::fromValue(true)); } void tst_QWebEngineScript::scriptModifications() @@ -253,6 +268,7 @@ private: QString m_text; }; +#if QT_CONFIG(webengine_webchannel) static QString readFile(const QString &path) { QFile file(path); @@ -318,7 +334,7 @@ void tst_QWebEngineScript::webChannel() if (worldId != QWebEngineScript::MainWorld) QCOMPARE(evaluateJavaScriptSync(&page, "qt.webChannelTransport"), QVariant(QVariant::Invalid)); } - +#endif void tst_QWebEngineScript::noTransportWithoutWebChannel() { QWebEnginePage page; @@ -382,7 +398,7 @@ void tst_QWebEngineScript::scriptsInNestedIframes() QWebEngineScript::ApplicationWorld), QVariant::fromValue(QStringLiteral("Modified Inner text"))); } - +#if QT_CONFIG(webengine_webchannel) void tst_QWebEngineScript::webChannelResettingAndUnsetting() { QWebEnginePage page; @@ -485,7 +501,7 @@ void tst_QWebEngineScript::webChannelWithBadString() QVERIFY(hostSpy.wait(20000)); QCOMPARE(host.text(), QString(QChar(QChar::ReplacementCharacter))); } - +#endif QTEST_MAIN(tst_QWebEngineScript) #include "tst_qwebenginescript.moc" |