diff options
19 files changed, 110 insertions, 244 deletions
diff --git a/src/core/api/qwebengineloadinginfo.cpp b/src/core/api/qwebengineloadinginfo.cpp index fcbb2ce7a..03a31ab72 100644 --- a/src/core/api/qwebengineloadinginfo.cpp +++ b/src/core/api/qwebengineloadinginfo.cpp @@ -56,9 +56,11 @@ Q_STATIC_ASSERT(static_cast<int>(WebEngineError::DnsErrorDomain) == static_cast< class QWebEngineLoadingInfo::QWebEngineLoadingInfoPrivate : public QSharedData { public: - QWebEngineLoadingInfoPrivate(const QUrl& url, LoadStatus status, const QString& errorString, int errorCode, ErrorDomain errorDomain) + QWebEngineLoadingInfoPrivate(const QUrl& url, LoadStatus status, bool isErrorPage, + const QString& errorString, int errorCode, ErrorDomain errorDomain) : url(url) , status(status) + , isErrorPage(isErrorPage) , errorString(errorString) , errorCode(errorCode) , errorDomain(errorDomain) @@ -67,6 +69,7 @@ public: QUrl url; LoadStatus status; + bool isErrorPage; QString errorString; int errorCode; ErrorDomain errorDomain; @@ -83,9 +86,9 @@ public: \sa QWebEnginePage::loadStarted, QWebEnginePage::loadFinished, WebEngineView::loadingChanged */ -QWebEngineLoadingInfo::QWebEngineLoadingInfo(const QUrl& url, LoadStatus status, const QString& errorString, - int errorCode, ErrorDomain errorDomain) - : d_ptr(new QWebEngineLoadingInfoPrivate(url, status, errorString, errorCode, errorDomain)) +QWebEngineLoadingInfo::QWebEngineLoadingInfo(const QUrl& url, LoadStatus status, bool isErrorPage, + const QString& errorString, int errorCode, ErrorDomain errorDomain) + : d_ptr(new QWebEngineLoadingInfoPrivate(url, status, isErrorPage, errorString, errorCode, errorDomain)) { } @@ -133,6 +136,18 @@ LoadStatus QWebEngineLoadingInfo::status() const return d->status; } /*! + \property QWebEngineLoadingInfo::isErrorPage + \property Indicates if the load's resulted in an error page. +*/ +/*! + Returns true if the load's resulted is an error page. +*/ +bool QWebEngineLoadingInfo::isErrorPage() const +{ + Q_D(const QWebEngineLoadingInfo); + return d->isErrorPage; +} +/*! \property QWebEngineLoadingInfo::errorString \brief Holds the error message. */ diff --git a/src/core/api/qwebengineloadinginfo.h b/src/core/api/qwebengineloadinginfo.h index bd07d52a3..8aacb0281 100644 --- a/src/core/api/qwebengineloadinginfo.h +++ b/src/core/api/qwebengineloadinginfo.h @@ -45,12 +45,18 @@ #include <QObject> #include <QUrl> +namespace QtWebEngineCore { +class WebContentsAdapter; +class WebContentsDelegateQt; +} + QT_BEGIN_NAMESPACE class Q_WEBENGINECORE_EXPORT QWebEngineLoadingInfo { Q_GADGET Q_PROPERTY(QUrl url READ url CONSTANT FINAL) + Q_PROPERTY(bool isErrorPage READ isErrorPage CONSTANT FINAL) Q_PROPERTY(LoadStatus status READ status CONSTANT FINAL) Q_PROPERTY(QString errorString READ errorString CONSTANT FINAL) Q_PROPERTY(ErrorDomain errorDomain READ errorDomain CONSTANT FINAL) @@ -83,19 +89,22 @@ public: ~QWebEngineLoadingInfo(); QUrl url() const; + bool isErrorPage() const; LoadStatus status() const; QString errorString() const; ErrorDomain errorDomain() const; int errorCode() const; private: - QWebEngineLoadingInfo(const QUrl& url, LoadStatus status, const QString& errorString = QString(), - int errorCode = 0, ErrorDomain errorDomain = NoErrorDomain); + QWebEngineLoadingInfo(const QUrl& url, LoadStatus status, + bool isErrorPage = false, const QString& errorString = QString(), + int errorCode = 0, ErrorDomain errorDomain = NoErrorDomain); class QWebEngineLoadingInfoPrivate; Q_DECLARE_PRIVATE(QWebEngineLoadingInfo) QExplicitlySharedDataPointer<QWebEngineLoadingInfoPrivate> d_ptr; friend class QQuickWebEngineViewPrivate; - friend class QQuickWebEngineErrorPage; + friend class QtWebEngineCore::WebContentsAdapter; + friend class QtWebEngineCore::WebContentsDelegateQt; }; QT_END_NAMESPACE diff --git a/src/core/api/qwebenginepage.cpp b/src/core/api/qwebenginepage.cpp index 460b5a351..5298849f8 100644 --- a/src/core/api/qwebenginepage.cpp +++ b/src/core/api/qwebenginepage.cpp @@ -52,6 +52,7 @@ #include "qwebenginefullscreenrequest.h" #include "qwebenginehistory.h" #include "qwebenginehistory_p.h" +#include "qwebengineloadinginfo.h" #include "qwebenginenavigationrequest.h" #include "qwebenginenewwindowrequest.h" #include "qwebenginenotification.h" @@ -300,31 +301,19 @@ QColor QWebEnginePagePrivate::backgroundColor() const return m_backgroundColor; } -void QWebEnginePagePrivate::loadStarted(const QUrl &provisionalUrl, bool isErrorPage) +void QWebEnginePagePrivate::loadStarted(QWebEngineLoadingInfo /* info */) { - Q_UNUSED(provisionalUrl); Q_Q(QWebEnginePage); - - if (isErrorPage) - return; - isLoading = true; - QTimer::singleShot(0, q, &QWebEnginePage::loadStarted); } -void QWebEnginePagePrivate::loadFinished(bool success, const QUrl &url, bool isErrorPage, int errorCode, const QString &errorDescription) +void QWebEnginePagePrivate::loadFinished(QWebEngineLoadingInfo info) { Q_Q(QWebEnginePage); - Q_UNUSED(url); - Q_UNUSED(errorCode); - Q_UNUSED(errorDescription); - - if (isErrorPage) - return; - isLoading = false; - QTimer::singleShot(0, q, [q, success](){ + bool success = info.status() == QWebEngineLoadingInfo::LoadSucceededStatus; + QTimer::singleShot(0, q, [q, success] () { emit q->loadFinished(success); }); } diff --git a/src/core/api/qwebenginepage_p.h b/src/core/api/qwebenginepage_p.h index a830028f8..46dcf2ce8 100644 --- a/src/core/api/qwebenginepage_p.h +++ b/src/core/api/qwebenginepage_p.h @@ -134,10 +134,10 @@ public: void renderProcessPidChanged(qint64 pid) override; QRectF viewportRect() const override; QColor backgroundColor() const override; - void loadStarted(const QUrl &provisionalUrl, bool isErrorPage = false) override; + void loadStarted(QWebEngineLoadingInfo info) override; void loadCommitted() override { } void didFirstVisuallyNonEmptyPaint() override { } - void loadFinished(bool success, const QUrl &url, bool isErrorPage, int errorCode, const QString &errorDescription) override; + void loadFinished(QWebEngineLoadingInfo info) override; void focusContainer() override; void unhandledKeyEvent(QKeyEvent *event) override; QSharedPointer<QtWebEngineCore::WebContentsAdapter> diff --git a/src/core/web_contents_adapter.cpp b/src/core/web_contents_adapter.cpp index 16e91e6c7..4c156644d 100644 --- a/src/core/web_contents_adapter.cpp +++ b/src/core/web_contents_adapter.cpp @@ -55,6 +55,7 @@ #include "profile_adapter.h" #include "profile_qt.h" #include "qwebenginecallback_p.h" +#include "qwebengineloadinginfo.h" #include "renderer_host/web_engine_page_host.h" #include "render_widget_host_view_qt.h" #include "type_conversion.h" @@ -721,10 +722,11 @@ void WebContentsAdapter::load(const QWebEngineHttpRequest &request) params.load_type = content::NavigationController::LOAD_TYPE_HTTP_POST; // chromium accepts LOAD_TYPE_HTTP_POST only for the HTTP and HTTPS protocols if (!params.url.SchemeIsHTTPOrHTTPS()) { - m_adapterClient->loadFinished(false, request.url(), false, - net::ERR_DISALLOWED_URL_SCHEME, - QCoreApplication::translate("WebContentsAdapter", - "HTTP-POST data can only be sent over HTTP(S) protocol")); + m_adapterClient->loadFinished(QWebEngineLoadingInfo( + request.url(), QWebEngineLoadingInfo::LoadFailedStatus, false, + QCoreApplication::translate("WebContentsAdapter", + "HTTP-POST data can only be sent over HTTP(S) protocol"), + net::ERR_DISALLOWED_URL_SCHEME)); return; } params.post_data = network::ResourceRequestBody::CreateFromBytes( @@ -779,7 +781,8 @@ void WebContentsAdapter::setContent(const QByteArray &data, const QString &mimeT GURL dataUrlToLoad(urlString); if (dataUrlToLoad.spec().size() > url::kMaxURLChars) { - m_adapterClient->loadFinished(false, baseUrl, false, net::ERR_ABORTED, QString()); + m_adapterClient->loadFinished(QWebEngineLoadingInfo(baseUrl, QWebEngineLoadingInfo::LoadFailedStatus, + false, QString(), net::ERR_ABORTED)); return; } content::NavigationController::LoadURLParams params((dataUrlToLoad)); diff --git a/src/core/web_contents_adapter_client.h b/src/core/web_contents_adapter_client.h index b0bddf5b8..42a5a3ab0 100644 --- a/src/core/web_contents_adapter_client.h +++ b/src/core/web_contents_adapter_client.h @@ -64,6 +64,7 @@ QT_FORWARD_DECLARE_CLASS(QKeyEvent) QT_FORWARD_DECLARE_CLASS(QVariant) QT_FORWARD_DECLARE_CLASS(QWebEngineFindTextResult) +QT_FORWARD_DECLARE_CLASS(QWebEngineLoadingInfo) QT_FORWARD_DECLARE_CLASS(QWebEngineQuotaRequest) QT_FORWARD_DECLARE_CLASS(QWebEngineRegisterProtocolHandlerRequest) QT_FORWARD_DECLARE_CLASS(QWebEngineUrlRequestInfo) @@ -192,10 +193,10 @@ public: virtual void renderProcessPidChanged(qint64 pid) = 0; virtual QRectF viewportRect() const = 0; virtual QColor backgroundColor() const = 0; - virtual void loadStarted(const QUrl &provisionalUrl, bool isErrorPage = false) = 0; + virtual void loadStarted(QWebEngineLoadingInfo info) = 0; virtual void loadCommitted() = 0; virtual void didFirstVisuallyNonEmptyPaint() = 0; - virtual void loadFinished(bool success, const QUrl &url, bool isErrorPage, int errorCode, const QString &errorDescription) = 0; + virtual void loadFinished(QWebEngineLoadingInfo info) = 0; virtual void focusContainer() = 0; virtual void unhandledKeyEvent(QKeyEvent *event) = 0; virtual QSharedPointer<WebContentsAdapter> diff --git a/src/core/web_contents_delegate_qt.cpp b/src/core/web_contents_delegate_qt.cpp index 34e1f7ad1..a04ef700b 100644 --- a/src/core/web_contents_delegate_qt.cpp +++ b/src/core/web_contents_delegate_qt.cpp @@ -49,6 +49,7 @@ #include "file_picker_controller.h" #include "media_capture_devices_dispatcher.h" #include "profile_qt.h" +#include "qwebengineloadinginfo.h" #include "qwebengineregisterprotocolhandlerrequest.h" #include "register_protocol_handler_request_controller_impl.h" #include "render_widget_host_view_qt.h" @@ -58,6 +59,7 @@ #include "web_contents_adapter.h" #include "web_contents_view_qt.h" #include "web_engine_context.h" +#include "web_engine_error.h" #include "web_engine_settings.h" #include "certificate_error_controller.h" #include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h" @@ -344,11 +346,9 @@ void WebContentsDelegateQt::emitLoadStarted(bool isErrorPage) m_isDocumentEmpty = true; // reset to default which may only be overridden on actual resource load complete if (!isErrorPage) { m_loadingInfo.progress = 0; - m_viewClient->loadStarted(m_loadingInfo.url, false); + m_viewClient->loadStarted(QWebEngineLoadingInfo(m_loadingInfo.url, QWebEngineLoadingInfo::LoadStartedStatus)); m_viewClient->updateNavigationActions(); m_viewClient->loadProgressChanged(0); - } else { - m_viewClient->loadStarted(toQt(GURL(content::kUnreachableWebDataURL)), true); } } @@ -374,17 +374,25 @@ void WebContentsDelegateQt::emitLoadFinished(bool isErrorPage) Q_ASSERT(!isErrorPage || webEngineSettings()->testAttribute(QWebEngineSettings::ErrorPageEnabled)); Q_ASSERT((m_loadingInfo.triggersErrorPage && webEngineSettings()->testAttribute(QWebEngineSettings::ErrorPageEnabled)) || !m_loadingInfo.triggersErrorPage); - if (!isErrorPage) { - if (m_loadingInfo.progress < 100) { - m_loadingInfo.progress = 100; - m_viewClient->loadProgressChanged(100); - } + if (isErrorPage) { + m_loadingInfo.isErrorPage = isErrorPage; + return; + } - m_viewClient->loadFinished(m_loadingInfo.success, m_loadingInfo.url, false, m_loadingInfo.errorCode, m_loadingInfo.errorDescription); - m_viewClient->updateNavigationActions(); - } else { - m_viewClient->loadFinished(false, toQt(GURL(content::kUnreachableWebDataURL)), true, 0, QString()); + if (m_loadingInfo.progress < 100) { + m_loadingInfo.progress = 100; + m_viewClient->loadProgressChanged(100); } + + auto loadStatus = m_loadingInfo.success + ? QWebEngineLoadingInfo::LoadSucceededStatus + : (m_loadingInfo.errorCode == WebEngineError::UserAbortedError + ? QWebEngineLoadingInfo::LoadStoppedStatus : QWebEngineLoadingInfo::LoadFailedStatus); + auto errorDomain = static_cast<QWebEngineLoadingInfo::ErrorDomain>(WebEngineError::toQtErrorDomain(m_loadingInfo.errorCode)); + QWebEngineLoadingInfo info(m_loadingInfo.url, loadStatus, m_loadingInfo.isErrorPage, + m_loadingInfo.errorDescription, m_loadingInfo.errorCode, errorDomain); + m_viewClient->loadFinished(std::move(info)); + m_viewClient->updateNavigationActions(); } void WebContentsDelegateQt::emitLoadCommitted() @@ -422,7 +430,6 @@ void WebContentsDelegateQt::DidFinishNavigation(content::NavigationHandle *navig // The load will succede as an error-page load later, and we reported the original error above if (navigation_handle->IsErrorPage()) { // Now report we are starting to load an error-page. - emitLoadStarted(true); // If it is already committed we will not see another DidFinishNavigation call or a DidFinishLoad call. if (navigation_handle->HasCommitted()) diff --git a/src/core/web_contents_delegate_qt.h b/src/core/web_contents_delegate_qt.h index d6adcd77c..9ddd1d192 100644 --- a/src/core/web_contents_delegate_qt.h +++ b/src/core/web_contents_delegate_qt.h @@ -237,6 +237,7 @@ private: int progress = -1; bool isLoading() const { return progress >= 0; } QUrl url; + bool isErrorPage = false; int errorCode = 0; QString errorDescription; bool triggersErrorPage = false; diff --git a/src/webenginequick/api/qquickwebenginetestsupport.cpp b/src/webenginequick/api/qquickwebenginetestsupport.cpp index d15472291..6c9e8ec30 100644 --- a/src/webenginequick/api/qquickwebenginetestsupport.cpp +++ b/src/webenginequick/api/qquickwebenginetestsupport.cpp @@ -52,25 +52,6 @@ namespace QTest { int Q_TESTLIB_EXPORT defaultMouseDelay(); } -QQuickWebEngineErrorPage::QQuickWebEngineErrorPage() -{ -} - -void QQuickWebEngineErrorPage::loadFinished(bool success, const QUrl &url) -{ - Q_UNUSED(success); - QTimer::singleShot(0, this, [this, url]() { - emit loadingChanged(QWebEngineLoadingInfo(url, QWebEngineLoadingInfo::LoadSucceededStatus)); - }); -} - -void QQuickWebEngineErrorPage::loadStarted(const QUrl &provisionalUrl) -{ - QTimer::singleShot(0, this, [this, provisionalUrl]() { - emit loadingChanged(QWebEngineLoadingInfo(provisionalUrl, QWebEngineLoadingInfo::LoadStartedStatus)); - }); -} - QQuickWebEngineTestInputContext::QQuickWebEngineTestInputContext() : m_visible(false) { @@ -167,17 +148,11 @@ void QQuickWebEngineTestEvent::mouseEvent(QEvent::Type type, QWindow *window, QO QQuickWebEngineTestSupport::QQuickWebEngineTestSupport() - : m_errorPage(new QQuickWebEngineErrorPage) - , m_testInputContext(new QQuickWebEngineTestInputContext) + : m_testInputContext(new QQuickWebEngineTestInputContext) , m_testEvent(new QQuickWebEngineTestEvent) { } -QQuickWebEngineErrorPage *QQuickWebEngineTestSupport::errorPage() const -{ - return m_errorPage.data(); -} - QQuickWebEngineTestInputContext *QQuickWebEngineTestSupport::testInputContext() const { return m_testInputContext.data(); diff --git a/src/webenginequick/api/qquickwebenginetestsupport_p.h b/src/webenginequick/api/qquickwebenginetestsupport_p.h index 0accb9b67..8f8bfde4d 100644 --- a/src/webenginequick/api/qquickwebenginetestsupport_p.h +++ b/src/webenginequick/api/qquickwebenginetestsupport_p.h @@ -63,19 +63,6 @@ QT_BEGIN_NAMESPACE class QWebEngineLoadingInfo; class QWindow; -class Q_WEBENGINE_PRIVATE_EXPORT QQuickWebEngineErrorPage : public QObject { - Q_OBJECT - -public: - QQuickWebEngineErrorPage(); - - void loadFinished(bool success, const QUrl &url); - void loadStarted(const QUrl &provisionalUrl); - -Q_SIGNALS: - void loadingChanged(const QWebEngineLoadingInfo &loadStatus); -}; - class Q_WEBENGINE_PRIVATE_EXPORT QQuickWebEngineTestInputContext : public QPlatformInputContext { Q_OBJECT @@ -110,13 +97,11 @@ private: class Q_WEBENGINE_PRIVATE_EXPORT QQuickWebEngineTestSupport : public QObject { Q_OBJECT - Q_PROPERTY(QQuickWebEngineErrorPage *errorPage READ errorPage CONSTANT FINAL) Q_PROPERTY(QQuickWebEngineTestInputContext *testInputContext READ testInputContext CONSTANT FINAL) Q_PROPERTY(QQuickWebEngineTestEvent *testEvent READ testEvent CONSTANT FINAL) public: QQuickWebEngineTestSupport(); - QQuickWebEngineErrorPage *errorPage() const; QQuickWebEngineTestInputContext *testInputContext() const; QQuickWebEngineTestEvent *testEvent() const; @@ -125,7 +110,6 @@ Q_SIGNALS: void loadVisuallyCommitted(); private: - QScopedPointer<QQuickWebEngineErrorPage> m_errorPage; QScopedPointer<QQuickWebEngineTestInputContext> m_testInputContext; QScopedPointer<QQuickWebEngineTestEvent> m_testEvent; }; diff --git a/src/webenginequick/api/qquickwebengineview.cpp b/src/webenginequick/api/qquickwebengineview.cpp index f457bb338..5a9e0f8fd 100644 --- a/src/webenginequick/api/qquickwebengineview.cpp +++ b/src/webenginequick/api/qquickwebengineview.cpp @@ -73,7 +73,6 @@ #include "render_widget_host_view_qt_delegate_quickwindow.h" #include "ui_delegates_manager.h" #include "web_contents_adapter.h" -#include "web_engine_error.h" #include "web_engine_settings.h" #include <QClipboard> @@ -455,22 +454,13 @@ QColor QQuickWebEngineViewPrivate::backgroundColor() const return m_backgroundColor; } -void QQuickWebEngineViewPrivate::loadStarted(const QUrl &provisionalUrl, bool isErrorPage) +void QQuickWebEngineViewPrivate::loadStarted(QWebEngineLoadingInfo info) { Q_Q(QQuickWebEngineView); - if (isErrorPage) { -#if QT_CONFIG(webenginequick_testsupport) - if (m_testSupport) - m_testSupport->errorPage()->loadStarted(provisionalUrl); -#endif - return; - } - isLoading = true; m_history->reset(); - - QTimer::singleShot(0, q, [q, provisionalUrl]() { - emit q->loadingChanged(QWebEngineLoadingInfo(provisionalUrl, LoadStatus::LoadStartedStatus)); + QTimer::singleShot(0, q, [q, info] () { + emit q->loadingChanged(info); }); } @@ -505,37 +495,13 @@ void QQuickWebEngineViewPrivate::didCompositorFrameSwap() #endif } -void QQuickWebEngineViewPrivate::loadFinished(bool success, const QUrl &url, bool isErrorPage, int errorCode, const QString &errorDescription) +void QQuickWebEngineViewPrivate::loadFinished(QWebEngineLoadingInfo info) { Q_Q(QQuickWebEngineView); - - if (isErrorPage) { -#if QT_CONFIG(webenginequick_testsupport) - if (m_testSupport) - m_testSupport->errorPage()->loadFinished(success, url); -#endif - return; - } - isLoading = false; m_history->reset(); - if (errorCode == WebEngineError::UserAbortedError) { - QTimer::singleShot(0, q, [q, url]() { - emit q->loadingChanged(QWebEngineLoadingInfo(url, LoadStatus::LoadStoppedStatus)); - }); - return; - } - if (success) { - QTimer::singleShot(0, q, [q, url, errorDescription, errorCode]() { - emit q->loadingChanged(QWebEngineLoadingInfo(url, LoadStatus::LoadSucceededStatus, errorDescription, errorCode)); - }); - return; - } - - Q_ASSERT(errorCode); - auto errorDomain = static_cast<ErrorDomain>(WebEngineError::toQtErrorDomain(errorCode)); - QTimer::singleShot(0, q, [q, url, errorDescription, errorCode, errorDomain]() { - emit q->loadingChanged(QWebEngineLoadingInfo(url, LoadStatus::LoadFailedStatus, errorDescription, errorCode, errorDomain)); + QTimer::singleShot(0, q, [q, info] () { + emit q->loadingChanged(info); }); return; } diff --git a/src/webenginequick/api/qquickwebengineview_p_p.h b/src/webenginequick/api/qquickwebengineview_p_p.h index f8bcadeb6..9dfaedfdd 100644 --- a/src/webenginequick/api/qquickwebengineview_p_p.h +++ b/src/webenginequick/api/qquickwebengineview_p_p.h @@ -115,10 +115,10 @@ public: void renderProcessPidChanged(qint64 pid) override; QRectF viewportRect() const override; QColor backgroundColor() const override; - void loadStarted(const QUrl &provisionalUrl, bool isErrorPage = false) override; + void loadStarted(QWebEngineLoadingInfo info) override; void loadCommitted() override; void didFirstVisuallyNonEmptyPaint() override; - void loadFinished(bool success, const QUrl &url, bool isErrorPage, int errorCode, const QString &errorDescription) override; + void loadFinished(QWebEngineLoadingInfo info) override; void focusContainer() override; void unhandledKeyEvent(QKeyEvent *event) override; QSharedPointer<QtWebEngineCore::WebContentsAdapter> diff --git a/src/webenginequick/testsupport/plugin.cpp b/src/webenginequick/testsupport/plugin.cpp index 087cd2919..02e6d66c4 100644 --- a/src/webenginequick/testsupport/plugin.cpp +++ b/src/webenginequick/testsupport/plugin.cpp @@ -56,8 +56,6 @@ public: Q_ASSERT(QLatin1String(uri) == QLatin1String("QtWebEngine.testsupport")); qmlRegisterType<QQuickWebEngineTestSupport>(uri, 1, 0, "WebEngineTestSupport"); - qmlRegisterUncreatableType<QQuickWebEngineErrorPage>(uri, 1, 0, "WebEngineErrorPage", - tr("Cannot create a separate instance of WebEngineErrorPage")); qmlRegisterUncreatableType<QQuickWebEngineTestInputContext>(uri, 1, 0, "TestInputContext", tr("Cannot create a separate instance of WebEngineErrorPage")); qmlRegisterUncreatableType<QQuickWebEngineTestEvent>(uri, 1, 0, "WebEngineTestEvent", diff --git a/src/webenginequick/testsupport/plugins.qmltypes b/src/webenginequick/testsupport/plugins.qmltypes index 17fb56658..cc39186ab 100644 --- a/src/webenginequick/testsupport/plugins.qmltypes +++ b/src/webenginequick/testsupport/plugins.qmltypes @@ -10,17 +10,6 @@ Module { dependencies: ["QtQuick 2.0"] Component { name: "QPlatformInputContext"; prototype: "QObject" } Component { - name: "QQuickWebEngineErrorPage" - prototype: "QObject" - exports: ["QtWebEngine.testsupport/WebEngineErrorPage 1.0"] - isCreatable: false - exportMetaObjectRevisions: [0] - Signal { - name: "loadingChanged" - Parameter { name: "loadingInfo"; type: "QWebEngineLoadingInfo" } - } - } - Component { name: "QQuickWebEngineTestEvent" prototype: "QObject" exports: ["QtWebEngine.testsupport/WebEngineTestEvent 1.0"] @@ -50,12 +39,6 @@ Module { exports: ["QtWebEngine.testsupport/WebEngineTestSupport 1.0"] exportMetaObjectRevisions: [0] Property { - name: "errorPage" - type: "QQuickWebEngineErrorPage" - isReadonly: true - isPointer: true - } - Property { name: "testInputContext" type: "QQuickWebEngineTestInputContext" isReadonly: true 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); |