summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2022-01-31 12:01:22 +0100
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2022-02-14 13:59:57 +0100
commitb8603c148c6cd53bdd82d0b712971cfc1b747780 (patch)
treefe5979b499db0c39e7cc8be766879f20e484b959 /tests
parent78819cdfc6738d1411e79b827c2d67b0739f4d3b (diff)
Add test for blocking of remote content
Pick-to: 6.3 6.2 Task-number: QTBUG-50686 Change-Id: Ie176bece1a44a6df608646e91171d02ceeea7e8f Reviewed-by: Michael BrĂ¼ning <michael.bruning@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/core/origins/resources/media.html15
-rw-r--r--tests/auto/core/origins/tst_origins.cpp33
2 files changed, 48 insertions, 0 deletions
diff --git a/tests/auto/core/origins/resources/media.html b/tests/auto/core/origins/resources/media.html
new file mode 100644
index 000000000..091485b61
--- /dev/null
+++ b/tests/auto/core/origins/resources/media.html
@@ -0,0 +1,15 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <title>Media</title>
+ <script>
+ function addAudio(src) {
+ let aud = document.createElement('audio')
+ aud.src = src
+ document.getElementsByTagName("body")[0].appendChild(aud)
+ }
+ </script>
+ </head>
+ <body>
+ </body>
+</html>
diff --git a/tests/auto/core/origins/tst_origins.cpp b/tests/auto/core/origins/tst_origins.cpp
index e07ec433c..6600bbc33 100644
--- a/tests/auto/core/origins/tst_origins.cpp
+++ b/tests/auto/core/origins/tst_origins.cpp
@@ -272,6 +272,7 @@ public:
const QString &) override
{
messages << message;
+ qCDebug(lc) << message;
}
QStringList messages;
};
@@ -298,6 +299,8 @@ private Q_SLOTS:
void mixedXHR();
void mixedContent_data();
void mixedContent();
+ void localMediaBlock_data();
+ void localMediaBlock();
#if defined(WEBSOCKETS)
void webSocket();
#endif
@@ -1293,5 +1296,35 @@ void tst_Origins::redirectInterceptor()
QCOMPARE(interceptor.requests[6], QUrl(QStringLiteral("redirect-secure:/resources/Akronim-Regular.woff2")));
}
+void tst_Origins::localMediaBlock_data()
+{
+ QTest::addColumn<bool>("enableAccess");
+ QTest::addRow("enabled") << true;
+ QTest::addRow("disabled") << false;
+}
+
+void tst_Origins::localMediaBlock()
+{
+ QFETCH(bool, enableAccess);
+
+ std::atomic<bool> accessed = false;
+ HttpServer server;
+ server.setResourceDirs({ QDir(QT_TESTCASE_SOURCEDIR).canonicalPath() + "/resources" });
+ connect(&server, &HttpServer::newRequest, [&](HttpReqRep *) { accessed.store(true); });
+ QVERIFY(server.start());
+
+ ScopedAttribute sa1(m_page->settings(), QWebEngineSettings::LocalContentCanAccessRemoteUrls, enableAccess);
+
+ QVERIFY(verifyLoad("file:" + QDir(QT_TESTCASE_SOURCEDIR).canonicalPath()
+ + "/resources/media.html"));
+ eval("addAudio('" + server.url("/mixedXHR.txt").toString() + "')");
+
+ // Give it a chance to avoid a false positive on the default value of accessed.
+ if (!enableAccess)
+ QTest::qSleep(500);
+ QTRY_COMPARE(accessed.load(), enableAccess);
+
+}
+
QTEST_MAIN(tst_Origins)
#include "tst_origins.moc"