From 5dd4dd1d1f83157339bac1600228895cc0c86088 Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Sun, 6 Jun 2021 18:30:13 +0200 Subject: Replace testsupport's QQuickWebEngineErrorPage with isErrorPage Merge and unify handling of loading started/finished for quick and widgets by removing separate quick's type for monitoring error page load and replace it with an isErrorPage method in WebEngineLoadRequest to indicate, that load ended with an error page being displayed. Effectively this only slightly changes when loading finished gets emitted: now the signal is just postponed until error page is finished loading after initial failure. [ChangeLog][QWebEngineQuick][WebEngineLoadingInfo] New property 'isErrorPage' which indicates that the load resulted in an error page Change-Id: I3e59dc488429d776f7c8e083b6d0489fb30a65fc Reviewed-by: Allan Sandfeld Jensen --- tests/auto/quick/publicapi/tst_publicapi.cpp | 2 +- tests/auto/quick/qmltests/CMakeLists.txt | 2 +- tests/auto/quick/qmltests/data/tst_favicon.qml | 3 - tests/auto/quick/qmltests/data/tst_loadFail.qml | 83 ++++++------------------ tests/auto/quick/qmltests/data/tst_viewSoure.qml | 37 +++-------- 5 files changed, 31 insertions(+), 96 deletions(-) (limited to 'tests/auto/quick') diff --git a/tests/auto/quick/publicapi/tst_publicapi.cpp b/tests/auto/quick/publicapi/tst_publicapi.cpp index 8f8227b44..c4188cd37 100644 --- a/tests/auto/quick/publicapi/tst_publicapi.cpp +++ b/tests/auto/quick/publicapi/tst_publicapi.cpp @@ -100,7 +100,6 @@ static const QStringList hardcodedTypes = QStringList() << "QQmlWebChannel*" // Ignore the testSupport types without making a fuss. << "QQuickWebEngineTestSupport*" - << "QQuickWebEngineErrorPage*" << "const QQuickWebEngineContextMenuData*" << "QWebEngineCookieStore*" << "Qt::LayoutDirection" @@ -316,6 +315,7 @@ static const QStringList expectedAPI = QStringList() << "QWebEngineLoadingInfo.errorString --> QString" << "QWebEngineLoadingInfo.status --> QWebEngineLoadingInfo::LoadStatus" << "QWebEngineLoadingInfo.url --> QUrl" + << "QWebEngineLoadingInfo.isErrorPage --> bool" << "QWebEngineLoadingInfo.LoadFailedStatus --> LoadStatus" << "QWebEngineLoadingInfo.LoadStartedStatus --> LoadStatus" << "QWebEngineLoadingInfo.LoadStoppedStatus --> LoadStatus" diff --git a/tests/auto/quick/qmltests/CMakeLists.txt b/tests/auto/quick/qmltests/CMakeLists.txt index fd756e6b9..55d4c74f5 100644 --- a/tests/auto/quick/qmltests/CMakeLists.txt +++ b/tests/auto/quick/qmltests/CMakeLists.txt @@ -25,6 +25,7 @@ set(testList tst_getUserMedia.qml tst_keyboardEvents.qml tst_keyboardModifierMapping.qml + tst_loadFail.qml tst_loadHtml.qml tst_loadProgress.qml tst_loadRecursionCrash.qml @@ -58,7 +59,6 @@ if(QT_FEATURE_webengine_testsupport) tst_inputMethod.qml tst_javaScriptDialogs.qml tst_linkHovered.qml - tst_loadFail.qml tst_mouseClick.qml tst_viewSoure.qml ) diff --git a/tests/auto/quick/qmltests/data/tst_favicon.qml b/tests/auto/quick/qmltests/data/tst_favicon.qml index 4d13d1e76..84b3db5e5 100644 --- a/tests/auto/quick/qmltests/data/tst_favicon.qml +++ b/tests/auto/quick/qmltests/data/tst_favicon.qml @@ -274,9 +274,6 @@ TestWebEngineView { var url = Qt.resolvedUrl("http://url.invalid") webEngineView.url = url verify(webEngineView.waitForLoadFailed(20000)) - // FIXME: Wait for error page load to finish. - // This should be done without testSupport API. - wait(500) compare(iconChangedSpy.count, 0) diff --git a/tests/auto/quick/qmltests/data/tst_loadFail.qml b/tests/auto/quick/qmltests/data/tst_loadFail.qml index c27ae8b0f..69a8bd274 100644 --- a/tests/auto/quick/qmltests/data/tst_loadFail.qml +++ b/tests/auto/quick/qmltests/data/tst_loadFail.qml @@ -29,7 +29,6 @@ import QtQuick 2.0 import QtTest 1.0 import QtWebEngine 1.2 -import QtWebEngine.testsupport 1.0 import "../../qmltests/data" 1.0 TestWebEngineView { @@ -38,47 +37,21 @@ TestWebEngineView { height: 300 property var unavailableUrl: Qt.resolvedUrl("file_that_does_not_exist.html") - property var loadRequestArray: [] - testSupport: WebEngineTestSupport { - property var errorPageLoadStatus: null - - function waitForErrorPageLoadSucceeded() { - var success = _waitFor(function() { return testSupport.errorPageLoadStatus == WebEngineView.LoadSucceededStatus }) - testSupport.errorPageLoadStatus = null - return success - } - - errorPage.onLoadingChanged: function(load) { - errorPageLoadStatus = load.status - - loadRequestArray.push({ - "status": load.status, - "url": load.url.toString(), - "errorDomain": load.errorDomain, - "isErrorPage": true - }) - } - } - - onLoadingChanged: function(load) { - if (load.status == WebEngineView.LoadFailedStatus) { - test.compare(load.url, unavailableUrl) - test.compare(load.errorDomain, WebEngineView.InternalErrorDomain) - } - - loadRequestArray.push({ - "status": load.status, - "url": load.url.toString(), - "errorDomain": load.errorDomain, - "isErrorPage": false - }) + SignalSpy { + id: loadSpy + target: webEngineView + signalName: 'loadingChanged' } TestCase { id: test name: "WebEngineViewLoadFail" + function cleanup() { + loadSpy.clear() + } + function test_fail() { WebEngine.settings.errorPageEnabled = false webEngineView.url = unavailableUrl @@ -106,39 +79,21 @@ TestWebEngineView { webEngineView.url = unavailableUrl // Loading of the error page must be successful - verify(webEngineView.testSupport.waitForErrorPageLoadSucceeded()) - - var loadRequest = null - compare(loadRequestArray.length, 4) + verify(webEngineView.waitForLoadFailed()) // Start to load unavailableUrl - loadRequest = loadRequestArray[0] - compare(loadRequest.status, WebEngineView.LoadStartedStatus) - compare(loadRequest.errorDomain, WebEngineView.NoErrorDomain) - compare(loadRequest.url, unavailableUrl) - verify(!loadRequest.isErrorPage) + let loadStart = loadSpy.signalArguments[0][0] + compare(loadStart.status, WebEngineView.LoadStartedStatus) + compare(loadStart.errorDomain, WebEngineView.NoErrorDomain) + compare(loadStart.url, unavailableUrl) + verify(!loadStart.isErrorPage) // Loading of the unavailableUrl must fail - loadRequest = loadRequestArray[3] - compare(loadRequest.status, WebEngineView.LoadFailedStatus) - compare(loadRequest.errorDomain, WebEngineView.InternalErrorDomain) - compare(loadRequest.url, unavailableUrl) - verify(!loadRequest.isErrorPage) - - // error page load is done inside main load through test support - // Start to load error page - loadRequest = loadRequestArray[1] - compare(loadRequest.status, WebEngineView.LoadStartedStatus) - compare(loadRequest.errorDomain, WebEngineView.NoErrorDomain) - compare(loadRequest.url, "chrome-error://chromewebdata/") - verify(loadRequest.isErrorPage) - - // Loading of the error page must be successful - loadRequest = loadRequestArray[2] - compare(loadRequest.status, WebEngineView.LoadSucceededStatus) - compare(loadRequest.errorDomain, WebEngineView.NoErrorDomain) - compare(loadRequest.url, "chrome-error://chromewebdata/") - verify(loadRequest.isErrorPage) + let loadFail = loadSpy.signalArguments[1][0] + compare(loadFail.status, WebEngineView.LoadFailedStatus) + compare(loadFail.errorDomain, WebEngineView.InternalErrorDomain) + compare(loadFail.url, unavailableUrl) + verify(loadFail.isErrorPage) compare(webEngineView.url, unavailableUrl) compare(webEngineView.title, unavailableUrl) diff --git a/tests/auto/quick/qmltests/data/tst_viewSoure.qml b/tests/auto/quick/qmltests/data/tst_viewSoure.qml index 1ee687f34..8d7c052aa 100644 --- a/tests/auto/quick/qmltests/data/tst_viewSoure.qml +++ b/tests/auto/quick/qmltests/data/tst_viewSoure.qml @@ -38,22 +38,11 @@ TestWebEngineView { height: 400 property var viewRequest: null - property var loadRequestArray: [] - - testSupport: WebEngineTestSupport { - errorPage.onLoadingChanged: function(load) { - loadRequestArray.push({ - "status": load.status, - "url": load.url - }) - } - } - onLoadingChanged: function(load) { - loadRequestArray.push({ - "status": load.status, - "url": load.url - }); + SignalSpy { + id: loadSpy + target: webEngineView + signalName: 'loadingChanged' } SignalSpy { @@ -87,6 +76,7 @@ TestWebEngineView { tryCompare(webEngineView, "loadStatus", WebEngineView.LoadSucceededStatus); webEngineView.loadStatus = null; + loadSpy.clear() newViewRequestedSpy.clear(); titleChangedSpy.clear(); viewRequest = null; @@ -107,21 +97,14 @@ TestWebEngineView { } function test_viewSourceURL(row) { - loadRequestArray = []; WebEngine.settings.errorPageEnabled = true webEngineView.url = row.userInputUrl; - - if (row.loadSucceed) { - tryVerify(function() { return loadRequestArray.length == 2 }); - compare(loadRequestArray[1].status, WebEngineView.LoadSucceededStatus); - } else { - tryVerify(function() { return loadRequestArray.length == 4 }, 90000); - // error page load is done inside main load through test support - compare(loadRequestArray[2].status, WebEngineView.LoadSucceededStatus); - compare(loadRequestArray[2].url, "chrome-error://chromewebdata/") - compare(loadRequestArray[3].status, WebEngineView.LoadFailedStatus); - } + tryCompare(loadSpy, 'count', 2); + let load = loadSpy.signalArguments[1][0] + let expectedStatus = row.loadSucceed ? WebEngineView.LoadSucceededStatus : WebEngineView.LoadFailedStatus + compare(load.status, expectedStatus); + compare(load.isErrorPage, !row.loadSucceed); tryVerify(function() { return titleChangedSpy.count == 1; }); compare(webEngineView.url, row.url); -- cgit v1.2.3