From b918c9fbee7cd1fd804000f0577516b0c0a2aa60 Mon Sep 17 00:00:00 2001
From: Peter Varga <pvarga@inf.u-szeged.hu>
Date: Thu, 6 Oct 2016 15:22:54 +0200
Subject: [PATCH] Refactor tst_keyboardModifierMapping.qml quick auto test

Simplify code and remove unnecessary wait calls.

Change-Id: If3a783a2a4f97e84de993b9394f5cfa0df948ec2
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
---
 .../data/tst_keyboardModifierMapping.qml      | 42 ++++++-------------
 1 file changed, 13 insertions(+), 29 deletions(-)

diff --git a/tests/auto/quick/qmltests/data/tst_keyboardModifierMapping.qml b/tests/auto/quick/qmltests/data/tst_keyboardModifierMapping.qml
index ae60e5f5e..e0a8c0a41 100644
--- a/tests/auto/quick/qmltests/data/tst_keyboardModifierMapping.qml
+++ b/tests/auto/quick/qmltests/data/tst_keyboardModifierMapping.qml
@@ -52,24 +52,26 @@ TestWebEngineView {
             onTriggered: parent.when = true
         }
 
+        function getPressedModifiers() {
+            var pressedModifiers;
+            runJavaScript("getPressedModifiers()", function(result) {
+                pressedModifiers = result;
+            });
+            tryVerify(function() { return pressedModifiers != undefined });
+            return pressedModifiers;
+        }
+
         function test_keyboardModifierMapping() {
             webEngineView.url = Qt.resolvedUrl("keyboardModifierMapping.html")
             waitForLoadSucceeded();
             titleSpy.wait()
-            var callbackCalled = false;
 
             // Alt
             keyPress(Qt.Key_Alt);
             titleSpy.wait()
-            runJavaScript("getPressedModifiers()", function(result) {
-                    compare(result, "alt:pressed ctrl:no meta:no");
-                    callbackCalled = true;
-                });
-            wait(100);
-            verify(callbackCalled);
+            compare(getPressedModifiers(), "alt:pressed ctrl:no meta:no");
             keyRelease(Qt.Key_Alt)
             titleSpy.wait()
-            callbackCalled = false;
 
             // Ctrl
             // On mac Qt automatically translates Meta to Ctrl and vice versa.
@@ -78,36 +80,18 @@ TestWebEngineView {
             // For testing we assume that the flag Qt::AA_MacDontSwapCtrlAndMeta is NOT set.
             keyPress(Qt.platform.os == "osx" ? Qt.Key_Meta : Qt.Key_Control);
             titleSpy.wait()
-            runJavaScript("getPressedModifiers()", function(result) {
-                    compare(result, "alt:released ctrl:pressed meta:no");
-                    callbackCalled = true;
-                });
-            wait(100);
-            verify(callbackCalled);
+            compare(getPressedModifiers(), "alt:released ctrl:pressed meta:no");
             keyRelease(Qt.platform.os == "osx" ? Qt.Key_Meta : Qt.Key_Control);
             titleSpy.wait()
-            callbackCalled = false;
 
             // Meta (Command on Mac)
             keyPress(Qt.platform.os == "osx" ? Qt.Key_Control : Qt.Key_Meta);
             titleSpy.wait()
-            runJavaScript("getPressedModifiers()", function(result) {
-                    compare(result, "alt:released ctrl:released meta:pressed");
-                    callbackCalled = true;
-                });
-            wait(100);
-            verify(callbackCalled);
+            compare(getPressedModifiers(), "alt:released ctrl:released meta:pressed");
             keyRelease(Qt.platform.os == "osx" ? Qt.Key_Control : Qt.Key_Meta);
             titleSpy.wait()
-            callbackCalled = false;
 
-            runJavaScript("getPressedModifiers()", function(result) {
-                    compare(result, "alt:released ctrl:released meta:released");
-                    callbackCalled = true;
-                });
-            wait(100);
-            verify(callbackCalled);
-            callbackCalled = false;
+            compare(getPressedModifiers(), "alt:released ctrl:released meta:released");
         }
     }
 }
-- 
GitLab