Skip to content

Commit b1296cd

Browse files
Kirill Burtsevpatricia-gallardo
authored andcommitted
Add test for LocalContentCanAccessRemoteUrls setting
Change-Id: Ia360553626c0277c7ef703504c8a7a76ca792801 Reviewed-by: Michael Brüning <[email protected]>
1 parent 5d4c669 commit b1296cd

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

tests/auto/widgets/origins/origins.pro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
include(../tests.pri)
2+
include(../../shared/http.pri)
23
CONFIG += c++14
34
qtConfig(webengine-webchannel):qtHaveModule(websockets) {
45
QT += websockets

tests/auto/widgets/origins/tst_origins.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
****************************************************************************/
2828

2929
#include "../util.h"
30+
#include "httpserver.h"
3031

3132
#include <QtCore/qfile.h>
3233
#include <QtTest/QtTest>
@@ -215,6 +216,8 @@ private Q_SLOTS:
215216
void jsUrlOrigin();
216217
void subdirWithAccess();
217218
void subdirWithoutAccess();
219+
void fileAccessRemoteUrl_data();
220+
void fileAccessRemoteUrl();
218221
void mixedSchemes();
219222
void mixedSchemesWithCsp();
220223
void mixedXHR_data();
@@ -497,6 +500,31 @@ void tst_Origins::subdirWithoutAccess()
497500
QCOMPARE(eval(QSL("msg[1]")), QVariant(QSL("world")));
498501
}
499502

503+
void tst_Origins::fileAccessRemoteUrl_data()
504+
{
505+
QTest::addColumn<bool>("EnableAccess");
506+
QTest::addRow("enabled") << true;
507+
QTest::addRow("disabled") << false;
508+
}
509+
510+
void tst_Origins::fileAccessRemoteUrl()
511+
{
512+
QFETCH(bool, EnableAccess);
513+
514+
HttpServer server;
515+
server.setResourceDirs({ THIS_DIR "resources" });
516+
QVERIFY(server.start());
517+
518+
ScopedAttribute sa(m_page->settings(), QWebEngineSettings::LocalContentCanAccessRemoteUrls, EnableAccess);
519+
if (!EnableAccess)
520+
QTest::ignoreMessage(QtSystemMsg, QRegularExpression(QSL("blocked by CORS policy")));
521+
522+
QVERIFY(verifyLoad(QSL("file:" THIS_DIR "resources/mixedXHR.html")));
523+
524+
eval("sendXHR('" + server.url("/mixedXHR.txt").toString() + "')");
525+
QTRY_COMPARE(eval("result"), (EnableAccess ? QString("ok") : QString("error")));
526+
}
527+
500528
// Load the main page over one scheme with an iframe over another scheme.
501529
//
502530
// For file and qrc schemes, the iframe should load but it should not be

0 commit comments

Comments
 (0)