From 2282c6605bc554ca610239f3dbc4d6d067c25763 Mon Sep 17 00:00:00 2001 From: Peter Varga <pvarga@inf.u-szeged.hu> Date: Wed, 22 Oct 2014 12:34:17 +0200 Subject: [PATCH] Make url handling consistent in widget and quick API Use explicit url in quick API too and use GetLastCommittedURL instead of GetVisibleURL for getting the expected urls in tests. Change-Id: If3251323645979643f3dc0e16491fe35b584f51c Reviewed-by: Andras Becsi <andras.becsi@digia.com> --- src/core/web_contents_adapter.cpp | 2 +- src/webengine/api/qquickwebengineview.cpp | 5 ++++- src/webengine/api/qquickwebengineview_p_p.h | 1 + src/webenginewidgets/api/qwebenginepage.cpp | 8 ++++---- src/webenginewidgets/api/qwebenginepage_p.h | 2 +- tests/auto/quick/qmltests/data/tst_loadUrl.qml | 4 +++- .../auto/widgets/qwebengineframe/tst_qwebengineframe.cpp | 2 -- 7 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/core/web_contents_adapter.cpp b/src/core/web_contents_adapter.cpp index 4129e8c33..3f223f733 100644 --- a/src/core/web_contents_adapter.cpp +++ b/src/core/web_contents_adapter.cpp @@ -448,7 +448,7 @@ void WebContentsAdapter::setContent(const QByteArray &data, const QString &mimeT QUrl WebContentsAdapter::activeUrl() const { Q_D(const WebContentsAdapter); - return toQt(d->webContents->GetVisibleURL()); + return toQt(d->webContents->GetLastCommittedURL()); } QUrl WebContentsAdapter::requestedUrl() const diff --git a/src/webengine/api/qquickwebengineview.cpp b/src/webengine/api/qquickwebengineview.cpp index b466c8566..ad850e84e 100644 --- a/src/webengine/api/qquickwebengineview.cpp +++ b/src/webengine/api/qquickwebengineview.cpp @@ -241,6 +241,7 @@ void QQuickWebEngineViewPrivate::urlChanged(const QUrl &url) { Q_Q(QQuickWebEngineView); Q_UNUSED(url); + explicitUrl = QUrl(); Q_EMIT q->urlChanged(); } @@ -309,6 +310,7 @@ void QQuickWebEngineViewPrivate::loadFinished(bool success, const QUrl &url, int return; } if (success) { + explicitUrl = QUrl(); QQuickWebEngineLoadRequest loadRequest(url, QQuickWebEngineView::LoadSucceededStatus); Q_EMIT q->loadingChanged(&loadRequest); return; @@ -506,7 +508,7 @@ QQuickWebEngineView::~QQuickWebEngineView() QUrl QQuickWebEngineView::url() const { Q_D(const QQuickWebEngineView); - return d->adapter->activeUrl(); + return d->explicitUrl.isValid() ? d->explicitUrl : d->adapter->activeUrl(); } void QQuickWebEngineView::setUrl(const QUrl& url) @@ -515,6 +517,7 @@ void QQuickWebEngineView::setUrl(const QUrl& url) return; Q_D(QQuickWebEngineView); + d->explicitUrl = url; d->adapter->load(url); } diff --git a/src/webengine/api/qquickwebengineview_p_p.h b/src/webengine/api/qquickwebengineview_p_p.h index ac8b8564f..6662f1f02 100644 --- a/src/webengine/api/qquickwebengineview_p_p.h +++ b/src/webengine/api/qquickwebengineview_p_p.h @@ -188,6 +188,7 @@ public: QScopedPointer<QQuickWebEngineHistory> m_history; QScopedPointer<QQuickWebEngineSettings> m_settings; QQmlComponent *contextMenuExtraItems; + QUrl explicitUrl; QUrl icon; int loadProgress; bool inspectable; diff --git a/src/webenginewidgets/api/qwebenginepage.cpp b/src/webenginewidgets/api/qwebenginepage.cpp index 8c3c2bb45..d6782974b 100644 --- a/src/webenginewidgets/api/qwebenginepage.cpp +++ b/src/webenginewidgets/api/qwebenginepage.cpp @@ -196,7 +196,7 @@ void QWebEnginePagePrivate::titleChanged(const QString &title) void QWebEnginePagePrivate::urlChanged(const QUrl &url) { Q_Q(QWebEnginePage); - m_explicitUrl = QUrl(); + explicitUrl = QUrl(); Q_EMIT q->urlChanged(url); } @@ -256,7 +256,7 @@ void QWebEnginePagePrivate::loadFinished(bool success, const QUrl &url, int erro Q_UNUSED(errorDescription); isLoading = false; if (success) - m_explicitUrl = QUrl(); + explicitUrl = QUrl(); Q_EMIT q->loadFinished(success); updateNavigationActions(); } @@ -825,14 +825,14 @@ QString QWebEnginePage::title() const void QWebEnginePage::setUrl(const QUrl &url) { Q_D(QWebEnginePage); - d->m_explicitUrl = url; + d->explicitUrl = url; load(url); } QUrl QWebEnginePage::url() const { Q_D(const QWebEnginePage); - return d->m_explicitUrl.isValid() ? d->m_explicitUrl : d->adapter->activeUrl(); + return d->explicitUrl.isValid() ? d->explicitUrl : d->adapter->activeUrl(); } QUrl QWebEnginePage::requestedUrl() const diff --git a/src/webenginewidgets/api/qwebenginepage_p.h b/src/webenginewidgets/api/qwebenginepage_p.h index ccbfb2bc1..54129229f 100644 --- a/src/webenginewidgets/api/qwebenginepage_p.h +++ b/src/webenginewidgets/api/qwebenginepage_p.h @@ -151,7 +151,7 @@ public: QWebEngineSettings *settings; QWebEngineView *view; QSize viewportSize; - QUrl m_explicitUrl; + QUrl explicitUrl; WebEngineContextMenuData m_menuData; bool isLoading; diff --git a/tests/auto/quick/qmltests/data/tst_loadUrl.qml b/tests/auto/quick/qmltests/data/tst_loadUrl.qml index 41faa6bc3..5f51e9036 100644 --- a/tests/auto/quick/qmltests/data/tst_loadUrl.qml +++ b/tests/auto/quick/qmltests/data/tst_loadUrl.qml @@ -125,7 +125,9 @@ TestWebEngineView { var handleLoadFailed = function(loadRequest) { if (loadRequest.status == WebEngineView.LoadFailedStatus) { webEngineView.loadHtml("load failed", bogusSite) - compare(webEngineView.url, bogusSite) + // Since the load did not succeed the active url is the + // url of the previous successful load. + compare(webEngineView.url, "about:blank") compare(loadRequest.url, bogusSite) } } diff --git a/tests/auto/widgets/qwebengineframe/tst_qwebengineframe.cpp b/tests/auto/widgets/qwebengineframe/tst_qwebengineframe.cpp index 1a8745f25..9901bcd76 100644 --- a/tests/auto/widgets/qwebengineframe/tst_qwebengineframe.cpp +++ b/tests/auto/widgets/qwebengineframe/tst_qwebengineframe.cpp @@ -1549,7 +1549,6 @@ void tst_QWebEngineFrame::setUrlThenLoads() // Just after first load. URL didn't changed yet. m_page->load(urlToLoad1); - QEXPECT_FAIL("", "Slight change: url() will return the loaded URL immediately.", Continue); QCOMPARE(m_page->url(), url); QCOMPARE(m_page->requestedUrl(), urlToLoad1); // baseUrlSync spins an event loop and this sometimes return the next result. @@ -1566,7 +1565,6 @@ void tst_QWebEngineFrame::setUrlThenLoads() // Just after second load. URL didn't changed yet. m_page->load(urlToLoad2); - QEXPECT_FAIL("", "Slight change: url() will return the loaded URL immediately.", Continue); QCOMPARE(m_page->url(), urlToLoad1); QCOMPARE(m_page->requestedUrl(), urlToLoad2); QCOMPARE(baseUrlSync(m_page), extractBaseUrl(urlToLoad1)); -- GitLab