summaryrefslogtreecommitdiffstats
path: root/tests/auto/core/qwebengineurlrequestinterceptor
diff options
context:
space:
mode:
authorMichael BrĂ¼ning <michael.bruning@qt.io>2019-01-18 16:26:29 +0100
committerMichael BrĂ¼ning <michael.bruning@qt.io>2019-01-18 16:26:29 +0100
commit819182302d5bdaba41efb68ef3c533b2acc19ae1 (patch)
treecab7a922998bc5d6e7f42b537b0c0ce1b69111f6 /tests/auto/core/qwebengineurlrequestinterceptor
parent0763b7c40d3490250f5bca1e0029cefba635305c (diff)
parent3f7ea91e23d82e676aeaf157736e25cf54e5ec6b (diff)
Merge remote-tracking branch 'origin/5.12' into dev
Conflicts: .qmake.conf src/core/net/network_delegate_qt.cpp src/core/profile_io_data_qt.cpp src/core/web_engine_context.h tests/auto/core/qwebengineurlrequestinterceptor/tst_qwebengineurlrequestinterceptor.cpp Change-Id: Id98e3f52f548ceb5b68abd80aedd6ae59db72cc0
Diffstat (limited to 'tests/auto/core/qwebengineurlrequestinterceptor')
-rw-r--r--tests/auto/core/qwebengineurlrequestinterceptor/resources/favicon.html7
-rw-r--r--tests/auto/core/qwebengineurlrequestinterceptor/resources/fontawesome.woffbin0 -> 6724 bytes
-rw-r--r--tests/auto/core/qwebengineurlrequestinterceptor/resources/icons/favicon.pngbin0 -> 3961 bytes
-rw-r--r--tests/auto/core/qwebengineurlrequestinterceptor/resources/iframe.html6
-rw-r--r--tests/auto/core/qwebengineurlrequestinterceptor/resources/iframe2.html6
-rw-r--r--tests/auto/core/qwebengineurlrequestinterceptor/resources/iframe3.html5
-rw-r--r--tests/auto/core/qwebengineurlrequestinterceptor/resources/image.html5
-rw-r--r--tests/auto/core/qwebengineurlrequestinterceptor/resources/image_in_iframe.html5
-rw-r--r--tests/auto/core/qwebengineurlrequestinterceptor/resources/media.html7
-rw-r--r--tests/auto/core/qwebengineurlrequestinterceptor/resources/media.mp4bin0 -> 1493 bytes
-rw-r--r--tests/auto/core/qwebengineurlrequestinterceptor/resources/media_in_iframe.html5
-rw-r--r--tests/auto/core/qwebengineurlrequestinterceptor/resources/resource.html9
-rw-r--r--tests/auto/core/qwebengineurlrequestinterceptor/resources/resource_in_iframe.html5
-rw-r--r--tests/auto/core/qwebengineurlrequestinterceptor/resources/script.js3
-rw-r--r--tests/auto/core/qwebengineurlrequestinterceptor/resources/style.css7
-rw-r--r--tests/auto/core/qwebengineurlrequestinterceptor/tst_qwebengineurlrequestinterceptor.cpp244
-rw-r--r--tests/auto/core/qwebengineurlrequestinterceptor/tst_qwebengineurlrequestinterceptor.qrc25
17 files changed, 321 insertions, 18 deletions
diff --git a/tests/auto/core/qwebengineurlrequestinterceptor/resources/favicon.html b/tests/auto/core/qwebengineurlrequestinterceptor/resources/favicon.html
new file mode 100644
index 000000000..5251d6ef7
--- /dev/null
+++ b/tests/auto/core/qwebengineurlrequestinterceptor/resources/favicon.html
@@ -0,0 +1,7 @@
+<html>
+<head>
+<link type="image/png" href="icons/favicon.png" sizes="48x48" rel="icon" />
+</head>
+<body>
+</body>
+</html>
diff --git a/tests/auto/core/qwebengineurlrequestinterceptor/resources/fontawesome.woff b/tests/auto/core/qwebengineurlrequestinterceptor/resources/fontawesome.woff
new file mode 100644
index 000000000..239b9c94e
--- /dev/null
+++ b/tests/auto/core/qwebengineurlrequestinterceptor/resources/fontawesome.woff
Binary files differ
diff --git a/tests/auto/core/qwebengineurlrequestinterceptor/resources/icons/favicon.png b/tests/auto/core/qwebengineurlrequestinterceptor/resources/icons/favicon.png
new file mode 100644
index 000000000..35717cca5
--- /dev/null
+++ b/tests/auto/core/qwebengineurlrequestinterceptor/resources/icons/favicon.png
Binary files differ
diff --git a/tests/auto/core/qwebengineurlrequestinterceptor/resources/iframe.html b/tests/auto/core/qwebengineurlrequestinterceptor/resources/iframe.html
new file mode 100644
index 000000000..f17027c7a
--- /dev/null
+++ b/tests/auto/core/qwebengineurlrequestinterceptor/resources/iframe.html
@@ -0,0 +1,6 @@
+<html>
+<body>
+<p>top</p>
+<iframe src="iframe2.html" width="80%" height="30%"/>
+</body>
+</html>
diff --git a/tests/auto/core/qwebengineurlrequestinterceptor/resources/iframe2.html b/tests/auto/core/qwebengineurlrequestinterceptor/resources/iframe2.html
new file mode 100644
index 000000000..758a44a2c
--- /dev/null
+++ b/tests/auto/core/qwebengineurlrequestinterceptor/resources/iframe2.html
@@ -0,0 +1,6 @@
+<html>
+<body>
+<p>another iframe</p>
+<iframe src="iframe3.html" width="80%" height="30%"></iframe>
+</body>
+</html>
diff --git a/tests/auto/core/qwebengineurlrequestinterceptor/resources/iframe3.html b/tests/auto/core/qwebengineurlrequestinterceptor/resources/iframe3.html
new file mode 100644
index 000000000..ed6ac5b94
--- /dev/null
+++ b/tests/auto/core/qwebengineurlrequestinterceptor/resources/iframe3.html
@@ -0,0 +1,5 @@
+<html>
+<body>
+<p>inner</p>
+</body>
+</html>
diff --git a/tests/auto/core/qwebengineurlrequestinterceptor/resources/image.html b/tests/auto/core/qwebengineurlrequestinterceptor/resources/image.html
new file mode 100644
index 000000000..b82e6aab2
--- /dev/null
+++ b/tests/auto/core/qwebengineurlrequestinterceptor/resources/image.html
@@ -0,0 +1,5 @@
+<html>
+<body>
+<img src="icons/favicon.png">
+</body>
+</html>
diff --git a/tests/auto/core/qwebengineurlrequestinterceptor/resources/image_in_iframe.html b/tests/auto/core/qwebengineurlrequestinterceptor/resources/image_in_iframe.html
new file mode 100644
index 000000000..2a3ac117c
--- /dev/null
+++ b/tests/auto/core/qwebengineurlrequestinterceptor/resources/image_in_iframe.html
@@ -0,0 +1,5 @@
+<html>
+<body>
+<iframe src="image.html"></iframe>
+</body>
+</html>
diff --git a/tests/auto/core/qwebengineurlrequestinterceptor/resources/media.html b/tests/auto/core/qwebengineurlrequestinterceptor/resources/media.html
new file mode 100644
index 000000000..fd478a679
--- /dev/null
+++ b/tests/auto/core/qwebengineurlrequestinterceptor/resources/media.html
@@ -0,0 +1,7 @@
+<html>
+<body>
+<video width="320" height="240" controls="">
+ <source src="media.mp4" type="video/mp4">
+</video>
+</body>
+</html>
diff --git a/tests/auto/core/qwebengineurlrequestinterceptor/resources/media.mp4 b/tests/auto/core/qwebengineurlrequestinterceptor/resources/media.mp4
new file mode 100644
index 000000000..1431e98dd
--- /dev/null
+++ b/tests/auto/core/qwebengineurlrequestinterceptor/resources/media.mp4
Binary files differ
diff --git a/tests/auto/core/qwebengineurlrequestinterceptor/resources/media_in_iframe.html b/tests/auto/core/qwebengineurlrequestinterceptor/resources/media_in_iframe.html
new file mode 100644
index 000000000..39e9bd9bb
--- /dev/null
+++ b/tests/auto/core/qwebengineurlrequestinterceptor/resources/media_in_iframe.html
@@ -0,0 +1,5 @@
+<html>
+<body>
+<iframe src="media.html"></iframe>
+</body>
+</html>
diff --git a/tests/auto/core/qwebengineurlrequestinterceptor/resources/resource.html b/tests/auto/core/qwebengineurlrequestinterceptor/resources/resource.html
new file mode 100644
index 000000000..040acee00
--- /dev/null
+++ b/tests/auto/core/qwebengineurlrequestinterceptor/resources/resource.html
@@ -0,0 +1,9 @@
+<html>
+<head>
+<link rel='stylesheet' href='style.css' type='text/css' />
+<script src="script.js"></script>
+</head>
+<body>
+<p>some text</p>
+</body>
+</html
diff --git a/tests/auto/core/qwebengineurlrequestinterceptor/resources/resource_in_iframe.html b/tests/auto/core/qwebengineurlrequestinterceptor/resources/resource_in_iframe.html
new file mode 100644
index 000000000..573182668
--- /dev/null
+++ b/tests/auto/core/qwebengineurlrequestinterceptor/resources/resource_in_iframe.html
@@ -0,0 +1,5 @@
+<html>
+<body>
+<iframe src="resource.html"></iframe>
+</body>
+</html>
diff --git a/tests/auto/core/qwebengineurlrequestinterceptor/resources/script.js b/tests/auto/core/qwebengineurlrequestinterceptor/resources/script.js
new file mode 100644
index 000000000..e6e0e8e7d
--- /dev/null
+++ b/tests/auto/core/qwebengineurlrequestinterceptor/resources/script.js
@@ -0,0 +1,3 @@
+var request = new XMLHttpRequest();
+request.open('GET', 'test', /* async = */ false);
+request.send();
diff --git a/tests/auto/core/qwebengineurlrequestinterceptor/resources/style.css b/tests/auto/core/qwebengineurlrequestinterceptor/resources/style.css
new file mode 100644
index 000000000..5ed3811e2
--- /dev/null
+++ b/tests/auto/core/qwebengineurlrequestinterceptor/resources/style.css
@@ -0,0 +1,7 @@
+@font-face {
+ font-family: fontawesome;
+ src: url(fontawesome.woff);
+}
+p {
+ font-family: fontawesome;
+}
diff --git a/tests/auto/core/qwebengineurlrequestinterceptor/tst_qwebengineurlrequestinterceptor.cpp b/tests/auto/core/qwebengineurlrequestinterceptor/tst_qwebengineurlrequestinterceptor.cpp
index 3f91f1b96..cdd5cfe28 100644
--- a/tests/auto/core/qwebengineurlrequestinterceptor/tst_qwebengineurlrequestinterceptor.cpp
+++ b/tests/auto/core/qwebengineurlrequestinterceptor/tst_qwebengineurlrequestinterceptor.cpp
@@ -28,6 +28,7 @@
#include "../../widgets/util.h"
#include <QtTest/QtTest>
+#include <QtWebEngineCore/qwebengineurlrequestinfo.h>
#include <QtWebEngineCore/qwebengineurlrequestinterceptor.h>
#include <QtWebEngineWidgets/qwebenginepage.h>
#include <QtWebEngineWidgets/qwebengineprofile.h>
@@ -55,6 +56,11 @@ private Q_SLOTS:
void setUrlSameUrl_data();
void setUrlSameUrl();
void firstPartyUrl();
+ void firstPartyUrlNestedIframes_data();
+ void firstPartyUrlNestedIframes();
+ void requestInterceptorByResourceType_data();
+ void requestInterceptorByResourceType();
+ void firstPartyUrlHttp();
};
tst_QWebEngineUrlRequestInterceptor::tst_QWebEngineUrlRequestInterceptor()
@@ -81,11 +87,22 @@ void tst_QWebEngineUrlRequestInterceptor::cleanupTestCase()
{
}
+struct RequestInfo {
+ RequestInfo(QWebEngineUrlRequestInfo &info)
+ : requestUrl(info.requestUrl())
+ , firstPartyUrl(info.firstPartyUrl())
+ , resourceType(info.resourceType())
+ {}
+
+ QUrl requestUrl;
+ QUrl firstPartyUrl;
+ int resourceType;
+};
+
class TestRequestInterceptor : public QWebEngineUrlRequestInterceptor
{
public:
- QList<QUrl> observedUrls;
- QList<QUrl> firstPartyUrls;
+ QList<RequestInfo> requestInfos;
bool shouldIntercept;
void interceptRequest(QWebEngineUrlRequestInfo &info) override
@@ -97,9 +114,51 @@ public:
if (shouldIntercept && info.requestUrl().toString().endsWith(QLatin1String("__placeholder__")))
info.redirect(QUrl("qrc:///resources/content.html"));
- observedUrls.append(info.requestUrl());
- firstPartyUrls.append(info.firstPartyUrl());
+ requestInfos.append(info);
+ }
+
+ bool shouldSkipRequest(const RequestInfo &requestInfo)
+ {
+ if (requestInfo.resourceType == QWebEngineUrlRequestInfo::ResourceTypeMainFrame ||
+ requestInfo.resourceType == QWebEngineUrlRequestInfo::ResourceTypeSubFrame)
+ return false;
+
+ // Skip import documents and sandboxed documents.
+ // See Document::SiteForCookies() in chromium/third_party/blink/renderer/core/dom/document.cc.
+ //
+ // TODO: Change this to empty URL during the next chromium update:
+ // https://chromium-review.googlesource.com/c/chromium/src/+/1213082/
+ return requestInfo.firstPartyUrl == QUrl("data:,");
+ }
+
+ QList<RequestInfo> getUrlRequestForType(QWebEngineUrlRequestInfo::ResourceType type)
+ {
+ QList<RequestInfo> infos;
+
+ foreach (auto requestInfo, requestInfos) {
+ if (shouldSkipRequest(requestInfo))
+ continue;
+
+ if (type == requestInfo.resourceType)
+ infos.append(requestInfo);
+ }
+
+ return infos;
+ }
+
+ bool hasUrlRequestForType(QWebEngineUrlRequestInfo::ResourceType type)
+ {
+ foreach (auto requestInfo, requestInfos) {
+ if (shouldSkipRequest(requestInfo))
+ continue;
+
+ if (type == requestInfo.resourceType)
+ return true;
+ }
+
+ return false;
}
+
TestRequestInterceptor(bool intercept)
: shouldIntercept(intercept)
{
@@ -137,7 +196,7 @@ void tst_QWebEngineUrlRequestInterceptor::interceptRequest()
// The redirection for __placeholder__ should succeed.
QVERIFY(success.toBool());
loadSpy.clear();
- QCOMPARE(interceptor.observedUrls.count(), 4);
+ QCOMPARE(interceptor.requestInfos.count(), 4);
// Make sure that registering an observer does not modify the request.
TestRequestInterceptor observer(/* intercept */ false);
@@ -147,7 +206,7 @@ void tst_QWebEngineUrlRequestInterceptor::interceptRequest()
success = loadSpy.takeFirst().takeFirst();
// Since we do not intercept, loading an invalid path should not succeed.
QVERIFY(!success.toBool());
- QCOMPARE(observer.observedUrls.count(), 1);
+ QCOMPARE(observer.requestInfos.count(), 1);
}
class LocalhostContentProvider : public QWebEngineUrlRequestInterceptor
@@ -218,19 +277,19 @@ void tst_QWebEngineUrlRequestInterceptor::requestedUrl()
page.setUrl(QUrl("qrc:///resources/__placeholder__"));
QVERIFY(spy.wait());
QTRY_COMPARE(spy.count(), 1);
- QCOMPARE(interceptor.observedUrls.at(0), QUrl("qrc:///resources/content.html"));
+ QCOMPARE(interceptor.requestInfos.at(0).requestUrl, QUrl("qrc:///resources/content.html"));
QCOMPARE(page.requestedUrl(), QUrl("qrc:///resources/__placeholder__"));
QCOMPARE(page.url(), QUrl("qrc:///resources/content.html"));
page.setUrl(QUrl("qrc:/non-existent.html"));
QTRY_COMPARE(spy.count(), 2);
- QCOMPARE(interceptor.observedUrls.at(2), QUrl("qrc:/non-existent.html"));
+ QCOMPARE(interceptor.requestInfos.at(2).requestUrl, QUrl("qrc:/non-existent.html"));
QCOMPARE(page.requestedUrl(), QUrl("qrc:///resources/__placeholder__"));
QCOMPARE(page.url(), QUrl("qrc:///resources/content.html"));
page.setUrl(QUrl("http://abcdef.abcdef"));
QTRY_COMPARE_WITH_TIMEOUT(spy.count(), 3, 15000);
- QCOMPARE(interceptor.observedUrls.at(3), QUrl("http://abcdef.abcdef/"));
+ QCOMPARE(interceptor.requestInfos.at(3).requestUrl, QUrl("http://abcdef.abcdef/"));
QCOMPARE(page.requestedUrl(), QUrl("qrc:///resources/__placeholder__"));
QCOMPARE(page.url(), QUrl("qrc:///resources/content.html"));
}
@@ -287,12 +346,171 @@ void tst_QWebEngineUrlRequestInterceptor::firstPartyUrl()
page.setUrl(QUrl("qrc:///resources/firstparty.html"));
QVERIFY(spy.wait());
- QCOMPARE(interceptor.observedUrls.at(0), QUrl("qrc:///resources/firstparty.html"));
- QCOMPARE(interceptor.observedUrls.at(1), QUrl("qrc:///resources/content.html"));
- QCOMPARE(interceptor.firstPartyUrls.at(0), QUrl("qrc:///resources/firstparty.html"));
- QCOMPARE(interceptor.firstPartyUrls.at(1), QUrl("qrc:///resources/firstparty.html"));
+ QCOMPARE(interceptor.requestInfos.at(0).requestUrl, QUrl("qrc:///resources/firstparty.html"));
+ QCOMPARE(interceptor.requestInfos.at(1).requestUrl, QUrl("qrc:///resources/content.html"));
+ QCOMPARE(interceptor.requestInfos.at(0).firstPartyUrl, QUrl("qrc:///resources/firstparty.html"));
+ QCOMPARE(interceptor.requestInfos.at(1).firstPartyUrl, QUrl("qrc:///resources/firstparty.html"));
QCOMPARE(spy.count(), 1);
}
+void tst_QWebEngineUrlRequestInterceptor::firstPartyUrlNestedIframes_data()
+{
+ QUrl url = QUrl::fromLocalFile(TESTS_SOURCE_DIR + QLatin1String("qwebengineurlrequestinterceptor/resources/iframe.html"));
+
+ QTest::addColumn<QUrl>("requestUrl");
+ QTest::newRow("file") << url;
+ QTest::newRow("qrc") << QUrl("qrc:///resources/iframe.html");
+}
+
+void tst_QWebEngineUrlRequestInterceptor::firstPartyUrlNestedIframes()
+{
+ QFETCH(QUrl, requestUrl);
+
+ if (requestUrl.scheme() == "file" && !QDir(TESTS_SOURCE_DIR).exists())
+ W_QSKIP(QString("This test requires access to resources found in '%1'").arg(TESTS_SOURCE_DIR).toLatin1().constData(), SkipAll);
+
+ QString adjustedUrl = requestUrl.adjusted(QUrl::RemoveFilename).toString();
+
+ QWebEngineProfile profile;
+ TestRequestInterceptor interceptor(/* intercept */ false);
+ profile.setRequestInterceptor(&interceptor);
+
+ QWebEnginePage page(&profile);
+ QSignalSpy loadSpy(&page, SIGNAL(loadFinished(bool)));
+ page.setUrl(requestUrl);
+ QTRY_COMPARE(loadSpy.count(), 1);
+
+ RequestInfo info = interceptor.requestInfos.at(0);
+ QCOMPARE(info.requestUrl, requestUrl);
+ QCOMPARE(info.firstPartyUrl, requestUrl);
+ QCOMPARE(info.resourceType, QWebEngineUrlRequestInfo::ResourceTypeMainFrame);
+
+ info = interceptor.requestInfos.at(1);
+ QCOMPARE(info.requestUrl, QUrl(adjustedUrl + "iframe2.html"));
+ QCOMPARE(info.firstPartyUrl, requestUrl);
+ QCOMPARE(info.resourceType, QWebEngineUrlRequestInfo::ResourceTypeSubFrame);
+
+ info = interceptor.requestInfos.at(2);
+ QCOMPARE(info.requestUrl, QUrl(adjustedUrl + "iframe3.html"));
+ QCOMPARE(info.firstPartyUrl, requestUrl);
+ QCOMPARE(info.resourceType, QWebEngineUrlRequestInfo::ResourceTypeSubFrame);
+}
+
+void tst_QWebEngineUrlRequestInterceptor::requestInterceptorByResourceType_data()
+{
+ QUrl firstPartyUrl = QUrl::fromLocalFile(TESTS_SOURCE_DIR + QLatin1String("qwebengineurlrequestinterceptor/resources/resource_in_iframe.html"));
+ QUrl styleRequestUrl = QUrl::fromLocalFile(TESTS_SOURCE_DIR + QLatin1String("qwebengineurlrequestinterceptor/resources/style.css"));
+ QUrl scriptRequestUrl = QUrl::fromLocalFile(TESTS_SOURCE_DIR + QLatin1String("qwebengineurlrequestinterceptor/resources/script.js"));
+ QUrl fontRequestUrl = QUrl::fromLocalFile(TESTS_SOURCE_DIR + QLatin1String("qwebengineurlrequestinterceptor/resources/fontawesome.woff"));
+ QUrl xhrRequestUrl = QUrl::fromLocalFile(TESTS_SOURCE_DIR + QLatin1String("qwebengineurlrequestinterceptor/resources/test"));
+ QUrl imageFirstPartyUrl = QUrl::fromLocalFile(TESTS_SOURCE_DIR + QLatin1String("qwebengineurlrequestinterceptor/resources/image_in_iframe.html"));
+ QUrl imageRequestUrl = QUrl::fromLocalFile(TESTS_SOURCE_DIR + QLatin1String("qwebengineurlrequestinterceptor/resources/icons/favicon.png"));
+ QUrl mediaFirstPartyUrl = QUrl::fromLocalFile(TESTS_SOURCE_DIR + QLatin1String("qwebengineurlrequestinterceptor/resources/media_in_iframe.html"));
+ QUrl mediaRequestUrl = QUrl::fromLocalFile(TESTS_SOURCE_DIR + QLatin1String("qwebengineurlrequestinterceptor/resources/media.mp4"));
+ QUrl faviconFirstPartyUrl = QUrl::fromLocalFile(TESTS_SOURCE_DIR + QLatin1String("qwebengineurlrequestinterceptor/resources/favicon.html"));
+ QUrl faviconRequestUrl = QUrl::fromLocalFile(TESTS_SOURCE_DIR + QLatin1String("qwebengineurlrequestinterceptor/resources/icons/favicon.png"));
+
+ QTest::addColumn<QUrl>("requestUrl");
+ QTest::addColumn<QUrl>("firstPartyUrl");
+ QTest::addColumn<int>("resourceType");
+
+ QTest::newRow("StyleSheet") << styleRequestUrl << firstPartyUrl << static_cast<int>(QWebEngineUrlRequestInfo::ResourceTypeStylesheet);
+ QTest::newRow("Script") << scriptRequestUrl << firstPartyUrl << static_cast<int>(QWebEngineUrlRequestInfo::ResourceTypeScript);
+ QTest::newRow("Image") << imageRequestUrl << imageFirstPartyUrl << static_cast<int>(QWebEngineUrlRequestInfo::ResourceTypeImage);
+ QTest::newRow("FontResource") << fontRequestUrl << firstPartyUrl << static_cast<int>(QWebEngineUrlRequestInfo::ResourceTypeFontResource);
+ QTest::newRow("Media") << mediaRequestUrl << mediaFirstPartyUrl << static_cast<int>(QWebEngineUrlRequestInfo::ResourceTypeMedia);
+ QTest::newRow("Favicon") << faviconRequestUrl << faviconFirstPartyUrl << static_cast<int>(QWebEngineUrlRequestInfo::ResourceTypeFavicon);
+ QTest::newRow("Xhr") << xhrRequestUrl << firstPartyUrl << static_cast<int>(QWebEngineUrlRequestInfo::ResourceTypeXhr);
+}
+
+void tst_QWebEngineUrlRequestInterceptor::requestInterceptorByResourceType()
+{
+ if (!QDir(TESTS_SOURCE_DIR).exists())
+ W_QSKIP(QString("This test requires access to resources found in '%1'").arg(TESTS_SOURCE_DIR).toLatin1().constData(), SkipAll);
+
+ QFETCH(QUrl, requestUrl);
+ QFETCH(QUrl, firstPartyUrl);
+ QFETCH(int, resourceType);
+
+ QWebEngineProfile profile;
+ TestRequestInterceptor interceptor(/* intercept */ false);
+ profile.setRequestInterceptor(&interceptor);
+
+ QWebEnginePage page(&profile);
+ QSignalSpy loadSpy(&page, SIGNAL(loadFinished(bool)));
+ page.setUrl(firstPartyUrl);
+ QTRY_COMPARE(loadSpy.count(), 1);
+
+ QTRY_COMPARE(interceptor.getUrlRequestForType(static_cast<QWebEngineUrlRequestInfo::ResourceType>(resourceType)).count(), 1);
+ QList<RequestInfo> infos = interceptor.getUrlRequestForType(static_cast<QWebEngineUrlRequestInfo::ResourceType>(resourceType));
+ QCOMPARE(infos.at(0).requestUrl, requestUrl);
+ QCOMPARE(infos.at(0).firstPartyUrl, firstPartyUrl);
+ QCOMPARE(infos.at(0).resourceType, resourceType);
+}
+
+void tst_QWebEngineUrlRequestInterceptor::firstPartyUrlHttp()
+{
+ QWebEngineProfile profile;
+ TestRequestInterceptor interceptor(/* intercept */ false);
+ profile.setRequestInterceptor(&interceptor);
+
+ QWebEnginePage page(&profile);
+ QSignalSpy loadSpy(&page, SIGNAL(loadFinished(bool)));
+ QUrl firstPartyUrl = QUrl("https://www.w3schools.com/tags/tryit.asp?filename=tryhtml5_video");
+ page.setUrl(QUrl(firstPartyUrl));
+ if (!loadSpy.wait(15000) || !loadSpy.at(0).at(0).toBool())
+ QSKIP("Couldn't load page from network, skipping test.");
+
+ QList<RequestInfo> infos;
+
+ // SubFrame
+ QTRY_VERIFY(interceptor.hasUrlRequestForType(QWebEngineUrlRequestInfo::ResourceTypeSubFrame));
+ infos = interceptor.getUrlRequestForType(QWebEngineUrlRequestInfo::ResourceTypeSubFrame);
+ foreach (auto info, infos)
+ QCOMPARE(info.firstPartyUrl, firstPartyUrl);
+
+ // Stylesheet
+ QTRY_VERIFY(interceptor.hasUrlRequestForType(QWebEngineUrlRequestInfo::ResourceTypeStylesheet));
+ infos = interceptor.getUrlRequestForType(QWebEngineUrlRequestInfo::ResourceTypeStylesheet);
+ foreach (auto info, infos)
+ QCOMPARE(info.firstPartyUrl, firstPartyUrl);
+
+ // Script
+ QTRY_VERIFY(interceptor.hasUrlRequestForType(QWebEngineUrlRequestInfo::ResourceTypeScript));
+ infos = interceptor.getUrlRequestForType(QWebEngineUrlRequestInfo::ResourceTypeScript);
+ foreach (auto info, infos)
+ QCOMPARE(info.firstPartyUrl, firstPartyUrl);
+
+ // Image
+ QTRY_VERIFY(interceptor.hasUrlRequestForType(QWebEngineUrlRequestInfo::ResourceTypeImage));
+ infos = interceptor.getUrlRequestForType(QWebEngineUrlRequestInfo::ResourceTypeImage);
+ foreach (auto info, infos)
+ QCOMPARE(info.firstPartyUrl, firstPartyUrl);
+
+ // FontResource
+ QTRY_VERIFY(interceptor.hasUrlRequestForType(QWebEngineUrlRequestInfo::ResourceTypeFontResource));
+ infos = interceptor.getUrlRequestForType(QWebEngineUrlRequestInfo::ResourceTypeFontResource);
+ foreach (auto info, infos)
+ QCOMPARE(info.firstPartyUrl, firstPartyUrl);
+
+ // Media
+ QTRY_VERIFY(interceptor.hasUrlRequestForType(QWebEngineUrlRequestInfo::ResourceTypeMedia));
+ infos = interceptor.getUrlRequestForType(QWebEngineUrlRequestInfo::ResourceTypeMedia);
+ foreach (auto info, infos)
+ QCOMPARE(info.firstPartyUrl, firstPartyUrl);
+
+ // Favicon
+ QTRY_VERIFY(interceptor.hasUrlRequestForType(QWebEngineUrlRequestInfo::ResourceTypeFavicon));
+ infos = interceptor.getUrlRequestForType(QWebEngineUrlRequestInfo::ResourceTypeFavicon);
+ foreach (auto info, infos)
+ QCOMPARE(info.firstPartyUrl, firstPartyUrl);
+
+ // XMLHttpRequest
+ QTRY_VERIFY(interceptor.hasUrlRequestForType(QWebEngineUrlRequestInfo::ResourceTypeXhr));
+ infos = interceptor.getUrlRequestForType(QWebEngineUrlRequestInfo::ResourceTypeXhr);
+ foreach (auto info, infos)
+ QCOMPARE(info.firstPartyUrl, firstPartyUrl);
+}
+
QTEST_MAIN(tst_QWebEngineUrlRequestInterceptor)
#include "tst_qwebengineurlrequestinterceptor.moc"
diff --git a/tests/auto/core/qwebengineurlrequestinterceptor/tst_qwebengineurlrequestinterceptor.qrc b/tests/auto/core/qwebengineurlrequestinterceptor/tst_qwebengineurlrequestinterceptor.qrc
index ca045e7fc..13dbb134e 100644
--- a/tests/auto/core/qwebengineurlrequestinterceptor/tst_qwebengineurlrequestinterceptor.qrc
+++ b/tests/auto/core/qwebengineurlrequestinterceptor/tst_qwebengineurlrequestinterceptor.qrc
@@ -1,7 +1,22 @@
<!DOCTYPE RCC><RCC version="1.0">
-<qresource>
- <file>resources/index.html</file>
- <file>resources/content.html</file>
- <file>resources/firstparty.html</file>
-</qresource>
+ <qresource prefix="/">
+ <file>resources/content.html</file>
+ <file>resources/favicon.html</file>
+ <file>resources/firstparty.html</file>
+ <file>resources/fontawesome.woff</file>
+ <file>resources/iframe.html</file>
+ <file>resources/iframe2.html</file>
+ <file>resources/iframe3.html</file>
+ <file>resources/image.html</file>
+ <file>resources/image_in_iframe.html</file>
+ <file>resources/index.html</file>
+ <file>resources/media.html</file>
+ <file>resources/media.mp4</file>
+ <file>resources/media_in_iframe.html</file>
+ <file>resources/resource.html</file>
+ <file>resources/resource_in_iframe.html</file>
+ <file>resources/script.js</file>
+ <file>resources/style.css</file>
+ <file>resources/icons/favicon.png</file>
+ </qresource>
</RCC>