diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2017-12-19 18:04:37 +0100 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2017-12-30 20:57:15 +0000 |
commit | dcd882be0dffbefd0753928f3d801ebe64cbc28c (patch) | |
tree | 76dd07d50880b06de8c2a6031008640d01db1298 /tests/auto | |
parent | dfcd401333f96e8146ab81b919286f8bae187790 (diff) |
Cleanup tst_QWebEngineScript::injectionPoint
The code was not correctly giving a function as argument to the
addEventHandler, and the whole logic was more complicated than it
needed to be.
Change-Id: I21e4e6bb6adf1071ae7eb2798d129224af8ef0fb
Reviewed-by: Peter Varga <pvarga@inf.u-szeged.hu>
Diffstat (limited to 'tests/auto')
-rw-r--r-- | tests/auto/widgets/qwebenginescript/tst_qwebenginescript.cpp | 31 |
1 files changed, 16 insertions, 15 deletions
diff --git a/tests/auto/widgets/qwebenginescript/tst_qwebenginescript.cpp b/tests/auto/widgets/qwebenginescript/tst_qwebenginescript.cpp index e614c74d8..d852ca902 100644 --- a/tests/auto/widgets/qwebenginescript/tst_qwebenginescript.cpp +++ b/tests/auto/widgets/qwebenginescript/tst_qwebenginescript.cpp @@ -81,15 +81,12 @@ void tst_QWebEngineScript::injectionPoint() s.setInjectionPoint(static_cast<QWebEngineScript::InjectionPoint>(injectionPoint)); s.setWorldId(QWebEngineScript::MainWorld); QWebEnginePage page; - page.scripts().insert(s); - page.setHtml(QStringLiteral("<html><head><script> var contents;") + testScript - + QStringLiteral("document.addEventListener(\"load\", setTimeout(function(event) {\ - document.body.innerText = contents;\ - }, 550));\ - </script></head><body></body></html>")); QSignalSpy spyFinished(&page, &QWebEnginePage::loadFinished); + page.scripts().insert(s); + page.setHtml(QStringLiteral("<html><head><script>") + testScript + QStringLiteral("</script></head><body></body></html>")); QVERIFY(spyFinished.wait()); - QTRY_COMPARE(evaluateJavaScriptSync(&page, "document.body.innerText"), QVariant::fromValue(QStringLiteral("SUCCESS"))); + const QVariant expected(QVariant::fromValue(QStringLiteral("SUCCESS"))); + QTRY_COMPARE(evaluateJavaScriptSync(&page, "document.myContents"), expected); } void tst_QWebEngineScript::injectionPoint_data() @@ -97,17 +94,21 @@ void tst_QWebEngineScript::injectionPoint_data() QTest::addColumn<int>("injectionPoint"); QTest::addColumn<QString>("testScript"); QTest::newRow("DocumentCreation") << static_cast<int>(QWebEngineScript::DocumentCreation) - << QStringLiteral("var contents = (typeof(foo) == \"undefined\")? \"FAILURE\" : \"SUCCESS\";"); + << QStringLiteral("document.myContents = (typeof(foo) == \"undefined\")? \"FAILURE\" : \"SUCCESS\";"); QTest::newRow("DocumentReady") << static_cast<int>(QWebEngineScript::DocumentReady) // use a zero timeout to make sure the user script got a chance to run as the order is undefined. << QStringLiteral("document.addEventListener(\"DOMContentLoaded\", function() {\ - setTimeout(function() {\ - contents = (typeof(foo) == \"undefined\")? \"FAILURE\" : \"SUCCESS\";\ - }, 0)});"); - QTest::newRow("Deferred") << static_cast<int>(QWebEngineScript::Deferred) - << QStringLiteral("document.addEventListener(\"load\", setTimeout(function(event) {\ - contents = (typeof(foo) == \"undefined\")? \"FAILURE\" : \"SUCCESS\";\ - }, 500));"); + setTimeout(function() {\ + document.myContents = (typeof(foo) == \"undefined\")? \"FAILURE\" : \"SUCCESS\";\ + }, 0)});"); + QTest::newRow("Deferred") << static_cast<int>(QWebEngineScript::DocumentReady) + << QStringLiteral("document.onreadystatechange = function() { \ + if (document.readyState == \"complete\") { \ + setTimeout(function() {\ + document.myContents = (typeof(foo) == \"undefined\")? \"FAILURE\" : \"SUCCESS\";\ + }, 0);\ + } \ + };"); } void tst_QWebEngineScript::scriptWorld() |