summaryrefslogtreecommitdiffstats
path: root/tests/auto/core/qwebengineurlrequestinterceptor
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2018-07-24 09:41:25 +0200
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2018-10-17 12:34:30 +0000
commit17bd9d9de2d424ef7f7a193e17d1619d6effec7b (patch)
tree049a423c6a2f091e1d0f9e2c8a2531ebbd9412fc /tests/auto/core/qwebengineurlrequestinterceptor
parent0b1025b8aea4aa0336671f7e908287d65490d120 (diff)
Add setRequestInterceptor to QWebEnginePage
Makes it possible to make page specific intercepts, and is at the same time safer by running in the UI-thread. [ChangeLog][QtWebEngineWidgets][QWebEnginePage] Added setRequestInterceptor, similar to the same call on profile except it operates on a per-page basis and on the UI-thread. Change-Id: Id5a7173156c25d0f030f00b6ef314d283c7c8cdd Reviewed-by: Jüri Valdmann <juri.valdmann@qt.io>
Diffstat (limited to 'tests/auto/core/qwebengineurlrequestinterceptor')
-rw-r--r--tests/auto/core/qwebengineurlrequestinterceptor/tst_qwebengineurlrequestinterceptor.cpp31
1 files changed, 28 insertions, 3 deletions
diff --git a/tests/auto/core/qwebengineurlrequestinterceptor/tst_qwebengineurlrequestinterceptor.cpp b/tests/auto/core/qwebengineurlrequestinterceptor/tst_qwebengineurlrequestinterceptor.cpp
index 50a3e6ff6..3f91f1b96 100644
--- a/tests/auto/core/qwebengineurlrequestinterceptor/tst_qwebengineurlrequestinterceptor.cpp
+++ b/tests/auto/core/qwebengineurlrequestinterceptor/tst_qwebengineurlrequestinterceptor.cpp
@@ -50,7 +50,9 @@ private Q_SLOTS:
void cleanupTestCase();
void interceptRequest();
void ipv6HostEncoding();
+ void requestedUrl_data();
void requestedUrl();
+ void setUrlSameUrl_data();
void setUrlSameUrl();
void firstPartyUrl();
};
@@ -190,14 +192,27 @@ void tst_QWebEngineUrlRequestInterceptor::ipv6HostEncoding()
QCOMPARE(contentProvider.requestedUrls.at(0), QUrl::fromEncoded("http://[::1]/test.xml"));
}
+void tst_QWebEngineUrlRequestInterceptor::requestedUrl_data()
+{
+ QTest::addColumn<bool>("interceptInPage");
+
+ QTest::newRow("Profile intercept") << false;
+ QTest::newRow("Page intercept") << true;
+}
+
void tst_QWebEngineUrlRequestInterceptor::requestedUrl()
{
+ QFETCH(bool, interceptInPage);
+
QWebEngineProfile profile;
profile.settings()->setAttribute(QWebEngineSettings::ErrorPageEnabled, false);
TestRequestInterceptor interceptor(/* intercept */ true);
- profile.setRequestInterceptor(&interceptor);
+ if (!interceptInPage)
+ profile.setRequestInterceptor(&interceptor);
QWebEnginePage page(&profile);
+ if (interceptInPage)
+ page.setRequestInterceptor(&interceptor);
QSignalSpy spy(&page, SIGNAL(loadFinished(bool)));
page.setUrl(QUrl("qrc:///resources/__placeholder__"));
@@ -214,19 +229,29 @@ void tst_QWebEngineUrlRequestInterceptor::requestedUrl()
QCOMPARE(page.url(), QUrl("qrc:///resources/content.html"));
page.setUrl(QUrl("http://abcdef.abcdef"));
- QTRY_COMPARE_WITH_TIMEOUT(spy.count(), 3, 12000);
+ QTRY_COMPARE_WITH_TIMEOUT(spy.count(), 3, 15000);
QCOMPARE(interceptor.observedUrls.at(3), QUrl("http://abcdef.abcdef/"));
QCOMPARE(page.requestedUrl(), QUrl("qrc:///resources/__placeholder__"));
QCOMPARE(page.url(), QUrl("qrc:///resources/content.html"));
}
+void tst_QWebEngineUrlRequestInterceptor::setUrlSameUrl_data()
+{
+ requestedUrl_data();
+}
+
void tst_QWebEngineUrlRequestInterceptor::setUrlSameUrl()
{
+ QFETCH(bool, interceptInPage);
+
QWebEngineProfile profile;
TestRequestInterceptor interceptor(/* intercept */ true);
- profile.setRequestInterceptor(&interceptor);
+ if (!interceptInPage)
+ profile.setRequestInterceptor(&interceptor);
QWebEnginePage page(&profile);
+ if (interceptInPage)
+ page.setRequestInterceptor(&interceptor);
QSignalSpy spy(&page, SIGNAL(loadFinished(bool)));
page.setUrl(QUrl("qrc:///resources/__placeholder__"));