From 1eb814230515ffb3417e0ac9533fc24847c1ebb9 Mon Sep 17 00:00:00 2001
From: Peter Varga <pvarga@inf.u-szeged.hu>
Date: Thu, 6 Oct 2016 16:52:14 +0200
Subject: [PATCH] Speculative fix of title check in quick auto tests

Title might be changed after a successful page load too. The order is
not guaranteed. Implement wait for the expected title change.

Task-number: QTBUG-56180
Change-Id: If8c529e6246fe9e8c93e41be84c8934c8ed8d729
Reviewed-by: Kai Koehne <kai.koehne@qt.io>
---
 tests/auto/quick/qmltests/BLACKLIST              |  6 ------
 tests/auto/quick/qmltests/data/tst_settings.qml  | 16 ++++++++--------
 .../auto/quick/qmltests/data/tst_viewSource.qml  | 12 ++++++------
 3 files changed, 14 insertions(+), 20 deletions(-)

diff --git a/tests/auto/quick/qmltests/BLACKLIST b/tests/auto/quick/qmltests/BLACKLIST
index 390e91988..375d89894 100644
--- a/tests/auto/quick/qmltests/BLACKLIST
+++ b/tests/auto/quick/qmltests/BLACKLIST
@@ -13,11 +13,5 @@ osx
 [WebEngineViewLoadUrl::test_urlProperty]
 windows
 
-[WebEngineViewSettings::test_javascriptDisabled]
-windows
-
-[WebEngineViewSource::test_viewSourceURL]
-windows
-
 [WebViewFindText::test_findTextManyMatches]
 *
diff --git a/tests/auto/quick/qmltests/data/tst_settings.qml b/tests/auto/quick/qmltests/data/tst_settings.qml
index aa3a6dc60..0c37d9569 100644
--- a/tests/auto/quick/qmltests/data/tst_settings.qml
+++ b/tests/auto/quick/qmltests/data/tst_settings.qml
@@ -56,7 +56,7 @@ TestWebEngineView {
 
             webEngineView.url = Qt.resolvedUrl("javascript.html");
             verify(webEngineView.waitForLoadSucceeded());
-            compare(webEngineView.title, "New Title");
+            tryCompare(webEngineView, "title", "New Title");
         }
 
         function test_javascriptDisabled() {
@@ -64,7 +64,7 @@ TestWebEngineView {
 
             webEngineView.url = Qt.resolvedUrl("javascript.html");
             verify(webEngineView.waitForLoadSucceeded());
-            compare(webEngineView.title, "Original Title");
+            tryCompare(webEngineView, "title", "Original Title");
         }
 
         function test_localStorageDisabled() {
@@ -73,7 +73,7 @@ TestWebEngineView {
 
             webEngineView.url = Qt.resolvedUrl("localStorage.html");
             verify(webEngineView.waitForLoadSucceeded());
-            compare(webEngineView.title, "Original Title");
+            tryCompare(webEngineView, "title", "Original Title");
         }
 
         function test_localStorageEnabled() {
@@ -84,7 +84,7 @@ TestWebEngineView {
             verify(webEngineView.waitForLoadSucceeded());
             webEngineView.reload();
             verify(webEngineView.waitForLoadSucceeded());
-            compare(webEngineView.title, "New Title");
+            tryCompare(webEngineView, "title", "New Title");
         }
 
         function test_settingsAffectCurrentViewOnly()  {
@@ -100,8 +100,8 @@ TestWebEngineView {
             webEngineView2.url = testUrl;
             verify(webEngineView2.waitForLoadSucceeded());
 
-            compare(webEngineView.title, "New Title");
-            compare(webEngineView2.title, "New Title");
+            tryCompare(webEngineView, "title", "New Title");
+            tryCompare(webEngineView2, "title", "New Title");
 
             webEngineView.settings.javascriptEnabled = false;
 
@@ -110,8 +110,8 @@ TestWebEngineView {
             webEngineView2.url = testUrl;
             verify(webEngineView2.waitForLoadSucceeded());
 
-            compare(webEngineView.title, "Original Title");
-            compare(webEngineView2.title, "New Title");
+            tryCompare(webEngineView, "title", "Original Title");
+            tryCompare(webEngineView2, "title", "New Title");
 
             webEngineView2.destroy();
         }
diff --git a/tests/auto/quick/qmltests/data/tst_viewSource.qml b/tests/auto/quick/qmltests/data/tst_viewSource.qml
index 79b097b80..8076d99f8 100644
--- a/tests/auto/quick/qmltests/data/tst_viewSource.qml
+++ b/tests/auto/quick/qmltests/data/tst_viewSource.qml
@@ -74,7 +74,7 @@ TestWebEngineView {
         function test_viewSource() {
             webEngineView.url = Qt.resolvedUrl("test1.html");
             verify(webEngineView.waitForLoadSucceeded());
-            compare(webEngineView.title, "Test page 1");
+            tryCompare(webEngineView, "title", "Test page 1");
             // FIXME(pvarga): Reintroduce this check in the fix for QTBUG-56117
             //verify(webEngineView.canViewSource, true);
 
@@ -83,14 +83,14 @@ TestWebEngineView {
             tryCompare(newViewRequestedSpy, "count", 1);
             verify(webEngineView.waitForLoadSucceeded());
             // The first titleChanged signal is emitted by adoptWebContents()
-            tryCompare(titleChangedSpy, "count", 2);
+            tryVerify(function() { return titleChangedSpy.count >= 2; });
 
             compare(viewRequest.destination, WebEngineView.NewViewInTab);
             verify(viewRequest.userInitiated);
             // FIXME(pvarga): Reintroduce this check in the fix for QTBUG-56117
             //verify(!webEngineView.canViewSource);
 
-            compare(webEngineView.title, "test1.html");
+            tryCompare(webEngineView, "title", "test1.html");
             compare(webEngineView.url, "view-source:" + Qt.resolvedUrl("test1.html"));
         }
 
@@ -114,14 +114,14 @@ TestWebEngineView {
 
             if (row.loadSucceed) {
                 verify(webEngineView.waitForLoadSucceeded());
-                tryCompare(titleChangedSpy, "count", 1);
+                tryVerify(function() { return titleChangedSpy.count >= 1; });
             } else {
                 verify(webEngineView.waitForLoadFailed());
-                tryCompare(titleChangedSpy, "count", 2);
+                tryVerify(function() { return titleChangedSpy.count >= 2; });
             }
 
             compare(webEngineView.url, row.url);
-            compare(webEngineView.title, row.title);
+            tryCompare(webEngineView, "title", row.title);
             // FIXME(pvarga): Reintroduce this check in the fix for QTBUG-56117
             //verify(!webEngineView.canViewSource);
         }
-- 
GitLab