From d96f8495b59878f50223a81a734ce0983539d8cf Mon Sep 17 00:00:00 2001
From: Allan Sandfeld Jensen <allan.jensen@qt.io>
Date: Tue, 24 Oct 2017 18:10:57 +0200
Subject: [PATCH] Stabilize tst_javaScriptDialogs similateUserGesture

It was only reading window.mousePressReceived once, which can sometimes
be before the click is processed.

Change-Id: Ia0a7067a202afa563696708e6df5aa9445335eb8
Reviewed-by: Peter Varga <pvarga@inf.u-szeged.hu>
---
 .../qmltests/data/tst_javaScriptDialogs.qml    | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/tests/auto/quick/qmltests/data/tst_javaScriptDialogs.qml b/tests/auto/quick/qmltests/data/tst_javaScriptDialogs.qml
index 44836d67c..07236c3be 100644
--- a/tests/auto/quick/qmltests/data/tst_javaScriptDialogs.qml
+++ b/tests/auto/quick/qmltests/data/tst_javaScriptDialogs.qml
@@ -83,6 +83,15 @@ TestWebEngineView {
             compare(webEngineView.title, "REJECTED")
 
         }
+        function readMousePressRecieved() {
+            var mousePressReceived;
+            runJavaScript("window.mousePressReceived", function(result) {
+                mousePressReceived = result;
+            });
+
+            _waitFor(function() { return mousePressReceived != undefined; });
+            return mousePressReceived;
+        }
 
         function simulateUserGesture() {
             // A user gesture after page load is required since Chromium 60 to allow showing
@@ -90,14 +99,7 @@ TestWebEngineView {
             // See https://www.chromestatus.com/feature/5082396709879808
             mouseClick(webEngineView, 10, 10, Qt.LeftButton)
 
-            var mousePressReceived;
-            runJavaScript("window.mousePressReceived", function(result) {
-                mousePressReceived = result;
-            });
-
-            tryVerify(function() {
-                return mousePressReceived != undefined
-            }, 5000);
+            tryVerify(readMousePressRecieved)
         }
 
         function test_confirmClose() {
-- 
GitLab