summaryrefslogtreecommitdiffstats
path: root/tests/auto/core/qwebengineurlrequestinterceptor
diff options
context:
space:
mode:
authorMichal Klocek <michal.klocek@qt.io>2021-02-11 10:03:24 +0100
committerMichal Klocek <michal.klocek@qt.io>2021-05-22 14:10:10 +0200
commit97dcbd4019456b9a1c567faddb0521b7505d80fc (patch)
tree9c77c5640b1563d853c79898cd64d87252fe8c41 /tests/auto/core/qwebengineurlrequestinterceptor
parentdd523573f2981cc58d4da0ec6e2b061a6172a8eb (diff)
Add tests to the cmake build
Use QT_TESTCASE_SOURCEDIR instead of TESTS_SOURCE_DIR. Introduce Test::HttpServer and Test::Util targets. Query shared data location from server. Clean up "shared" resources. Note QT_TESTCASE_SOURCEDIR must be turned into the canonical form since the user can call on windows: "cmake \path\to\foo" instead of "cmake c:\path\to\foo" which will break all file:// urls. Note this patch breaks qmake builds. Task-number: QTBUG-91760 Change-Id: Ibc1f904ac9acd375d1ff70ff80f0c533497e3f20 Reviewed-by: Michael BrĂ¼ning <michael.bruning@qt.io>
Diffstat (limited to 'tests/auto/core/qwebengineurlrequestinterceptor')
-rw-r--r--tests/auto/core/qwebengineurlrequestinterceptor/CMakeLists.txt41
-rw-r--r--tests/auto/core/qwebengineurlrequestinterceptor/tst_qwebengineurlrequestinterceptor.cpp62
2 files changed, 84 insertions, 19 deletions
diff --git a/tests/auto/core/qwebengineurlrequestinterceptor/CMakeLists.txt b/tests/auto/core/qwebengineurlrequestinterceptor/CMakeLists.txt
new file mode 100644
index 000000000..fa6de9ef5
--- /dev/null
+++ b/tests/auto/core/qwebengineurlrequestinterceptor/CMakeLists.txt
@@ -0,0 +1,41 @@
+include(../../util/util.cmake)
+include(../../httpserver/httpserver.cmake)
+
+qt_internal_add_test(tst_qwebengineurlrequestinterceptor
+ SOURCES
+ tst_qwebengineurlrequestinterceptor.cpp
+ LIBRARIES
+ Qt::WebEngineWidgets
+ Test::HttpServer
+ Test::Util
+)
+
+set(tst_qwebengineurlrequestinterceptor_resource_files
+ "resources/content.html"
+ "resources/favicon.html"
+ "resources/firstparty.html"
+ "resources/fontawesome.woff"
+ "resources/icons/favicon.png"
+ "resources/iframe.html"
+ "resources/iframe2.html"
+ "resources/iframe3.html"
+ "resources/image.html"
+ "resources/image_in_iframe.html"
+ "resources/index.html"
+ "resources/media.html"
+ "resources/media.mp4"
+ "resources/media_in_iframe.html"
+ "resources/resource.html"
+ "resources/resource_in_iframe.html"
+ "resources/script.js"
+ "resources/style.css"
+ "resources/sw.html"
+ "resources/sw.js"
+)
+
+qt_add_resource(tst_qwebengineurlrequestinterceptor "tst_qwebengineurlrequestinterceptor"
+ PREFIX
+ "/"
+ FILES
+ ${tst_qwebengineurlrequestinterceptor_resource_files}
+)
diff --git a/tests/auto/core/qwebengineurlrequestinterceptor/tst_qwebengineurlrequestinterceptor.cpp b/tests/auto/core/qwebengineurlrequestinterceptor/tst_qwebengineurlrequestinterceptor.cpp
index 34ef111f2..8a6cbb331 100644
--- a/tests/auto/core/qwebengineurlrequestinterceptor/tst_qwebengineurlrequestinterceptor.cpp
+++ b/tests/auto/core/qwebengineurlrequestinterceptor/tst_qwebengineurlrequestinterceptor.cpp
@@ -26,7 +26,7 @@
**
****************************************************************************/
-#include "../../widgets/util.h"
+#include <util.h>
#include <QtTest/QtTest>
#include <QtWebEngineCore/qwebengineurlrequestinfo.h>
#include <QtWebEngineCore/qwebengineurlrequestinterceptor.h>
@@ -416,7 +416,8 @@ void tst_QWebEngineUrlRequestInterceptor::firstPartyUrl()
void tst_QWebEngineUrlRequestInterceptor::firstPartyUrlNestedIframes_data()
{
- QUrl url = QUrl::fromLocalFile(TESTS_SOURCE_DIR + QLatin1String("qwebengineurlrequestinterceptor/resources/iframe.html"));
+ QUrl url = QUrl::fromLocalFile(QDir(QT_TESTCASE_SOURCEDIR).canonicalPath()
+ + QLatin1String("/resources/iframe.html"));
QTest::addColumn<QUrl>("requestUrl");
QTest::newRow("ui file") << url;
QTest::newRow("ui qrc") << QUrl("qrc:///resources/iframe.html");
@@ -426,8 +427,13 @@ 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);
+ if (requestUrl.scheme() == "file"
+ && !QDir(QDir(QT_TESTCASE_SOURCEDIR).canonicalPath()).exists())
+ W_QSKIP(QString("This test requires access to resources found in '%1'")
+ .arg(QDir(QT_TESTCASE_SOURCEDIR).canonicalPath())
+ .toLatin1()
+ .constData(),
+ SkipAll);
QString adjustedUrl = requestUrl.adjusted(QUrl::RemoveFilename).toString();
@@ -461,17 +467,30 @@ void tst_QWebEngineUrlRequestInterceptor::firstPartyUrlNestedIframes()
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"));
+ QUrl firstPartyUrl = QUrl::fromLocalFile(QDir(QT_TESTCASE_SOURCEDIR).canonicalPath()
+ + QLatin1String("/resources/resource_in_iframe.html"));
+ QUrl styleRequestUrl = QUrl::fromLocalFile(QDir(QT_TESTCASE_SOURCEDIR).canonicalPath()
+ + QLatin1String("/resources/style.css"));
+ QUrl scriptRequestUrl = QUrl::fromLocalFile(QDir(QT_TESTCASE_SOURCEDIR).canonicalPath()
+ + QLatin1String("/resources/script.js"));
+ QUrl fontRequestUrl = QUrl::fromLocalFile(QDir(QT_TESTCASE_SOURCEDIR).canonicalPath()
+ + QLatin1String("/resources/fontawesome.woff"));
+ QUrl xhrRequestUrl = QUrl::fromLocalFile(QDir(QT_TESTCASE_SOURCEDIR).canonicalPath()
+ + QLatin1String("/resources/test"));
+ QUrl imageFirstPartyUrl =
+ QUrl::fromLocalFile(QDir(QT_TESTCASE_SOURCEDIR).canonicalPath()
+ + QLatin1String("/resources/image_in_iframe.html"));
+ QUrl imageRequestUrl = QUrl::fromLocalFile(QDir(QT_TESTCASE_SOURCEDIR).canonicalPath()
+ + QLatin1String("/resources/icons/favicon.png"));
+ QUrl mediaFirstPartyUrl =
+ QUrl::fromLocalFile(QDir(QT_TESTCASE_SOURCEDIR).canonicalPath()
+ + QLatin1String("/resources/media_in_iframe.html"));
+ QUrl mediaRequestUrl = QUrl::fromLocalFile(QDir(QT_TESTCASE_SOURCEDIR).canonicalPath()
+ + QLatin1String("/resources/media.mp4"));
+ QUrl faviconFirstPartyUrl = QUrl::fromLocalFile(QDir(QT_TESTCASE_SOURCEDIR).canonicalPath()
+ + QLatin1String("/resources/favicon.html"));
+ QUrl faviconRequestUrl = QUrl::fromLocalFile(QDir(QT_TESTCASE_SOURCEDIR).canonicalPath()
+ + QLatin1String("/resources/icons/favicon.png"));
QTest::addColumn<QUrl>("requestUrl");
QTest::addColumn<QUrl>("firstPartyUrl");
@@ -498,8 +517,12 @@ void tst_QWebEngineUrlRequestInterceptor::requestInterceptorByResourceType_data(
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);
+ if (!QDir(QDir(QT_TESTCASE_SOURCEDIR).canonicalPath()).exists())
+ W_QSKIP(QString("This test requires access to resources found in '%1'")
+ .arg(QDir(QT_TESTCASE_SOURCEDIR).canonicalPath())
+ .toLatin1()
+ .constData(),
+ SkipAll);
QFETCH(QUrl, requestUrl);
QFETCH(QUrl, firstPartyUrl);
QFETCH(int, resourceType);
@@ -583,7 +606,8 @@ void tst_QWebEngineUrlRequestInterceptor::customHeaders()
{
// Create HTTP Server to parse the request.
HttpServer httpServer;
- httpServer.setResourceDirs({ TESTS_SOURCE_DIR "qwebengineurlrequestinterceptor/resources" });
+ httpServer.setResourceDirs({ QDir(QT_TESTCASE_SOURCEDIR).canonicalPath()
+ + "/resources" });
QVERIFY(httpServer.start());
QWebEngineProfile profile;
@@ -700,7 +724,7 @@ void tst_QWebEngineUrlRequestInterceptor::jsServiceWorker()
{
HttpServer server;
- server.setResourceDirs({ TESTS_SOURCE_DIR "qwebengineurlrequestinterceptor/resources" });
+ server.setResourceDirs({ QDir(QT_TESTCASE_SOURCEDIR).canonicalPath() + "/resources" });
QVERIFY(server.start());
QWebEngineProfile profile(QStringLiteral("Test"));