File indexing completed on 2025-01-26 04:57:24
0001 /* 0002 SPDX-FileCopyrightText: 2020-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "blockexternalresourcesurlinterceptortest.h" 0008 #include <QStandardPaths> 0009 #include <QTest> 0010 #include <WebEngineViewer/BlockExternalResourcesUrlInterceptor> 0011 QTEST_GUILESS_MAIN(BlockExternalResourcesUrlInterceptorTest) 0012 BlockExternalResourcesUrlInterceptorTest::BlockExternalResourcesUrlInterceptorTest(QObject *parent) 0013 : QObject(parent) 0014 { 0015 QStandardPaths::setTestModeEnabled(true); 0016 } 0017 0018 void BlockExternalResourcesUrlInterceptorTest::shouldIntercept() 0019 { 0020 WebEngineViewer::BlockExternalResourcesUrlInterceptor interceptor; 0021 QVERIFY(!interceptor.interceptRequest(QUrl(QStringLiteral("file://")), 0022 QWebEngineUrlRequestInfo::ResourceType::ResourceTypeMedia, 0023 QWebEngineUrlRequestInfo::NavigationType::NavigationTypeReload)); 0024 QVERIFY(!interceptor.interceptRequest(QUrl(QStringLiteral("data://")), 0025 QWebEngineUrlRequestInfo::ResourceType::ResourceTypeMedia, 0026 QWebEngineUrlRequestInfo::NavigationType::NavigationTypeReload)); 0027 QVERIFY(interceptor.interceptRequest(QUrl(QStringLiteral("ftp://")), 0028 QWebEngineUrlRequestInfo::ResourceType::ResourceTypeUnknown, 0029 QWebEngineUrlRequestInfo::NavigationType::NavigationTypeReload)); 0030 QVERIFY(interceptor.interceptRequest(QUrl(QStringLiteral("ftp://")), 0031 QWebEngineUrlRequestInfo::ResourceType::ResourceTypePing, 0032 QWebEngineUrlRequestInfo::NavigationType::NavigationTypeReload)); 0033 QVERIFY(!interceptor.interceptRequest(QUrl(QStringLiteral("ftp://")), 0034 QWebEngineUrlRequestInfo::ResourceType::ResourceTypeMainFrame, 0035 QWebEngineUrlRequestInfo::NavigationType::NavigationTypeLink)); 0036 QVERIFY(interceptor.interceptRequest(QUrl(QStringLiteral("ftp://")), 0037 QWebEngineUrlRequestInfo::ResourceType::ResourceTypeMainFrame, 0038 QWebEngineUrlRequestInfo::NavigationType::NavigationTypeRedirect)); 0039 } 0040 0041 #include "moc_blockexternalresourcesurlinterceptortest.cpp"