summaryrefslogtreecommitdiffstats
path: root/tests/auto/core
diff options
context:
space:
mode:
authorKirill Burtsev <kirill.burtsev@qt.io>2020-08-27 14:44:50 +0200
committerKirill Burtsev <kirill.burtsev@qt.io>2020-09-01 06:10:30 +0200
commit99b5a45fea6c19dbf65cf5a151be01a6cd0c36e7 (patch)
tree0cb13e8b997e1e15f4880d4fb69b12fa7550b9ee /tests/auto/core
parentf59e8fdf97ad0933eda2c88acd4de70bd318035d (diff)
Do not call deprecated profile interceptor on ui thread
Otherwise unchanged intercepted request leads to second call in the same interceptor but on ui thread after io thread. Ammends a05bb73747. Fixes: QTBUG-86267 Change-Id: I4e7c662d24a58be5445f5c8b6d0bf3751f40cc05 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'tests/auto/core')
-rw-r--r--tests/auto/core/qwebengineurlrequestinterceptor/tst_qwebengineurlrequestinterceptor.cpp37
1 files changed, 27 insertions, 10 deletions
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);