summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/core/net/proxying_url_loader_factory_qt.cpp2
-rw-r--r--tests/auto/core/qwebengineurlrequestinterceptor/tst_qwebengineurlrequestinterceptor.cpp37
2 files changed, 28 insertions, 11 deletions
diff --git a/src/core/net/proxying_url_loader_factory_qt.cpp b/src/core/net/proxying_url_loader_factory_qt.cpp
index b42aa64bb..8e084a40b 100644
--- a/src/core/net/proxying_url_loader_factory_qt.cpp
+++ b/src/core/net/proxying_url_loader_factory_qt.cpp
@@ -258,7 +258,7 @@ void InterceptedRequest::InterceptOnIOThread(base::WaitableEvent *event)
void InterceptedRequest::InterceptOnUIThread()
{
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
- if (profile_request_interceptor_)
+ if (profile_request_interceptor_ && !profile_request_interceptor_->property("deprecated").toBool())
profile_request_interceptor_->interceptRequest(request_info_);
if (!request_info_.changed() && page_request_interceptor_)
diff --git a/tests/auto/core/qwebengineurlrequestinterceptor/tst_qwebengineurlrequestinterceptor.cpp b/tests/auto/core/qwebengineurlrequestinterceptor/tst_qwebengineurlrequestinterceptor.cpp
index 350c15174..5d845dcdb 100644
--- a/tests/auto/core/qwebengineurlrequestinterceptor/tst_qwebengineurlrequestinterceptor.cpp
+++ b/tests/auto/core/qwebengineurlrequestinterceptor/tst_qwebengineurlrequestinterceptor.cpp
@@ -118,29 +118,42 @@ struct RequestInfo {
static const QByteArray kHttpHeaderReferrerValue = QByteArrayLiteral("http://somereferrer.com/");
static const QByteArray kHttpHeaderRefererName = QByteArrayLiteral("referer");
+static const QUrl kRedirectUrl = QUrl("qrc:///resources/content.html");
class TestRequestInterceptor : public QWebEngineUrlRequestInterceptor
{
public:
QList<RequestInfo> requestInfos;
- bool shouldIntercept;
+ bool shouldRedirect = false;
QMap<QUrl, QSet<QUrl>> requestInitiatorUrls;
+ QMap<QByteArray, QByteArray> headers;
void interceptRequest(QWebEngineUrlRequestInfo &info) override
{
QCOMPARE(QThread::currentThread() == QCoreApplication::instance()->thread(), !property("deprecated").toBool());
+
// Since 63 we also intercept some unrelated blob requests..
if (info.requestUrl().scheme() == QLatin1String("blob"))
return;
- info.block(info.requestMethod() != QByteArrayLiteral("GET"));
- if (shouldIntercept && info.requestUrl().toString().endsWith(QLatin1String("__placeholder__")))
- info.redirect(QUrl("qrc:///resources/content.html"));
- // Set referrer header
- info.setHttpHeader(kHttpHeaderRefererName, kHttpHeaderReferrerValue);
+ bool block = info.requestMethod() != QByteArrayLiteral("GET");
+ bool redirect = shouldRedirect && info.requestUrl() != kRedirectUrl;
+
+ if (block) {
+ info.block(true);
+ } else if (redirect) {
+ info.redirect(kRedirectUrl);
+ } else {
+ // set additional headers if any required by test
+ for (auto it = headers.begin(); it != headers.end(); ++it) info.setHttpHeader(it.key(), it.value());
+ }
requestInitiatorUrls[info.requestUrl()].insert(info.initiator());
requestInfos.append(info);
+
+ // MEMO avoid unintentionally changing request when it is not needed for test logic
+ // since api behavior depends on 'changed' state of the info object
+ Q_ASSERT(info.changed() == (block || redirect || !headers.empty()));
}
bool shouldSkipRequest(const RequestInfo &requestInfo)
@@ -182,8 +195,8 @@ public:
return false;
}
- TestRequestInterceptor(bool intercept)
- : shouldIntercept(intercept)
+ TestRequestInterceptor(bool redirect)
+ : shouldRedirect(redirect)
{
}
};
@@ -252,7 +265,7 @@ void tst_QWebEngineUrlRequestInterceptor::interceptRequest()
QFETCH(InterceptorSetter, setter);
QWebEngineProfile profile;
profile.settings()->setAttribute(QWebEngineSettings::ErrorPageEnabled, false);
- TestRequestInterceptor interceptor(/* intercept */ true);
+ TestRequestInterceptor interceptor(/* intercept */ false);
(profile.*setter)(&interceptor);
QWebEnginePage page(&profile);
QSignalSpy loadSpy(&page, SIGNAL(loadFinished(bool)));
@@ -272,6 +285,7 @@ void tst_QWebEngineUrlRequestInterceptor::interceptRequest()
QVERIFY(!success.toBool());
loadSpy.clear();
+ interceptor.shouldRedirect = true;
page.load(QUrl("qrc:///resources/__placeholder__"));
QTRY_COMPARE(loadSpy.count(), 1);
success = loadSpy.takeFirst().takeFirst();
@@ -372,6 +386,8 @@ void tst_QWebEngineUrlRequestInterceptor::requestedUrl()
QCOMPARE(page.requestedUrl(), QUrl("qrc:///resources/__placeholder__"));
QCOMPARE(page.url(), QUrl("qrc:///resources/content.html"));
+ interceptor.shouldRedirect = false;
+
page.setUrl(QUrl("qrc:/non-existent.html"));
QTRY_COMPARE(spy.count(), 2);
QVERIFY(interceptor.requestInfos.count() >= 3);
@@ -668,7 +684,8 @@ void tst_QWebEngineUrlRequestInterceptor::passRefererHeader()
});
QWebEngineProfile profile;
- TestRequestInterceptor interceptor(true);
+ TestRequestInterceptor interceptor(false);
+ interceptor.headers.insert(kHttpHeaderRefererName, kHttpHeaderReferrerValue);
(profile.*setter)(&interceptor);
QWebEnginePage page(&profile);