From 93745b5452c2ec69c04be2a2043c0937327ee556 Mon Sep 17 00:00:00 2001 From: Joerg Bornemann Date: Thu, 12 Nov 2015 09:54:02 +0100 Subject: stabilize tst_QWebEngineScript::injectionPoint Use QTRY_COMPARE instead of a hard-coded timeout. Fix usage of setTimeout in DOMContentLoaded event listener. Change-Id: I915ea0d2c54cf45be42803963d03b19c15135fd4 Reviewed-by: Allan Sandfeld Jensen --- tests/auto/widgets/qwebenginescript/tst_qwebenginescript.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'tests/auto/widgets/qwebenginescript/tst_qwebenginescript.cpp') diff --git a/tests/auto/widgets/qwebenginescript/tst_qwebenginescript.cpp b/tests/auto/widgets/qwebenginescript/tst_qwebenginescript.cpp index 80445051c..53762f54c 100644 --- a/tests/auto/widgets/qwebenginescript/tst_qwebenginescript.cpp +++ b/tests/auto/widgets/qwebenginescript/tst_qwebenginescript.cpp @@ -83,8 +83,7 @@ void tst_QWebEngineScript::injectionPoint() }, 550));\ ")); waitForSignal(&page, SIGNAL(loadFinished(bool))); - QTest::qWait(550); - QCOMPARE(evaluateJavaScriptSync(&page, "document.body.innerText"), QVariant::fromValue(QStringLiteral("SUCCESS"))); + QTRY_COMPARE(evaluateJavaScriptSync(&page, "document.body.innerText"), QVariant::fromValue(QStringLiteral("SUCCESS"))); } void tst_QWebEngineScript::injectionPoint_data() @@ -95,9 +94,10 @@ void tst_QWebEngineScript::injectionPoint_data() << QStringLiteral("var contents = (typeof(foo) == \"undefined\")? \"FAILURE\" : \"SUCCESS\";"); QTest::newRow("DocumentReady") << static_cast(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\", setTimeout(function(event) {\ + << QStringLiteral("document.addEventListener(\"DOMContentLoaded\", function() {\ + setTimeout(function() {\ contents = (typeof(foo) == \"undefined\")? \"FAILURE\" : \"SUCCESS\";\ - }, 0));"); + }, 0)});"); QTest::newRow("Deferred") << static_cast(QWebEngineScript::Deferred) << QStringLiteral("document.addEventListener(\"load\", setTimeout(function(event) {\ contents = (typeof(foo) == \"undefined\")? \"FAILURE\" : \"SUCCESS\";\ -- cgit v1.2.3