Commit 2e1e7d36 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Add autotest

parent 524771f1
Pipeline #24331 passed with stage
in 44 minutes and 43 seconds
......@@ -48,6 +48,7 @@ if(BUILD_TESTING)
add_subdirectory(widgets/autotests/)
add_subdirectory(utils/autotests)
add_subdirectory(viewer/renderer/autotests)
add_subdirectory(viewer/webengine/blockexternalresourcesurlinterceptor/autotests)
endif()
add_subdirectory(pics)
add_subdirectory(kconf_update)
......
macro(add_messageviewer_blockexternalresource_unittest _source)
get_filename_component(_name ${_source} NAME_WE)
ecm_add_test(${_source}
TEST_NAME ${_name}
NAME_PREFIX "messageviewer-"
LINK_LIBRARIES KF5::MessageViewer KF5::WebEngineViewer Qt5::Test
)
endmacro ()
add_messageviewer_blockexternalresource_unittest(blockexternalresourcesurlinterceptortest.cpp)
/*
Copyright (C) 2020 Laurent Montel <montel@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "blockexternalresourcesurlinterceptortest.h"
#include "viewer/webengine/blockexternalresourcesurlinterceptor/blockexternalresourcesurlinterceptor.h"
#include <qtwebenginewidgetsversion.h>
#include <QTest>
QTEST_MAIN(BlockExternalResourcesUrlInterceptorTest)
BlockExternalResourcesUrlInterceptorTest::BlockExternalResourcesUrlInterceptorTest(QObject *parent)
: QObject(parent)
{
}
void BlockExternalResourcesUrlInterceptorTest::shouldIntercept()
{
MessageViewer::BlockExternalResourcesUrlInterceptor interceptor;
QVERIFY(!interceptor.interceptRequest(QStringLiteral("file"), QWebEngineUrlRequestInfo::ResourceType::ResourceTypeMedia, QWebEngineUrlRequestInfo::NavigationType::NavigationTypeReload));
QVERIFY(!interceptor.interceptRequest(QStringLiteral("data"), QWebEngineUrlRequestInfo::ResourceType::ResourceTypeMedia, QWebEngineUrlRequestInfo::NavigationType::NavigationTypeReload));
QVERIFY(interceptor.interceptRequest(QStringLiteral("ftp"), QWebEngineUrlRequestInfo::ResourceType::ResourceTypeUnknown, QWebEngineUrlRequestInfo::NavigationType::NavigationTypeReload));
QVERIFY(interceptor.interceptRequest(QStringLiteral("ftp"), QWebEngineUrlRequestInfo::ResourceType::ResourceTypePing, QWebEngineUrlRequestInfo::NavigationType::NavigationTypeReload));
QVERIFY(!interceptor.interceptRequest(QStringLiteral("ftp"), QWebEngineUrlRequestInfo::ResourceType::ResourceTypeMainFrame, QWebEngineUrlRequestInfo::NavigationType::NavigationTypeLink));
#if QTWEBENGINEWIDGETS_VERSION >= QT_VERSION_CHECK(5, 14, 0)
QVERIFY(interceptor.interceptRequest(QStringLiteral("ftp"), QWebEngineUrlRequestInfo::ResourceType::ResourceTypeMainFrame, QWebEngineUrlRequestInfo::NavigationType::NavigationTypeRedirect));
#endif
}
/*
Copyright (C) 2020 Laurent Montel <montel@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef BLOCKEXTERNALRESOURCESURLINTERCEPTORTEST_H
#define BLOCKEXTERNALRESOURCESURLINTERCEPTORTEST_H
#include <QObject>
class BlockExternalResourcesUrlInterceptorTest : public QObject
{
Q_OBJECT
public:
explicit BlockExternalResourcesUrlInterceptorTest(QObject *parent = nullptr);
~BlockExternalResourcesUrlInterceptorTest() = default;
private Q_SLOTS:
void shouldIntercept();
};
#endif // BLOCKEXTERNALRESOURCESURLINTERCEPTORTEST_H
......@@ -33,17 +33,13 @@ BlockExternalResourcesUrlInterceptor::~BlockExternalResourcesUrlInterceptor()
{
}
bool BlockExternalResourcesUrlInterceptor::interceptRequest(QWebEngineUrlRequestInfo &info)
bool BlockExternalResourcesUrlInterceptor::interceptRequest(const QString &scheme, QWebEngineUrlRequestInfo::ResourceType resourceType, QWebEngineUrlRequestInfo::NavigationType navigationType)
{
const QString scheme = info.requestUrl().scheme();
if (scheme == QLatin1String("data")
|| scheme == QLatin1String("file")) {
return false;
}
const QWebEngineUrlRequestInfo::ResourceType resourceType = info.resourceType();
const QWebEngineUrlRequestInfo::NavigationType navigationType = info.navigationType();
if (resourceType == QWebEngineUrlRequestInfo::ResourceTypeMedia
|| resourceType == QWebEngineUrlRequestInfo::ResourceTypePing
|| resourceType == QWebEngineUrlRequestInfo::ResourceTypePrefetch
......@@ -73,4 +69,14 @@ bool BlockExternalResourcesUrlInterceptor::interceptRequest(QWebEngineUrlRequest
return true;
}
return false;
}
bool BlockExternalResourcesUrlInterceptor::interceptRequest(QWebEngineUrlRequestInfo &info)
{
const QString scheme = info.requestUrl().scheme();
const QWebEngineUrlRequestInfo::ResourceType resourceType = info.resourceType();
const QWebEngineUrlRequestInfo::NavigationType navigationType = info.navigationType();
return interceptRequest(scheme, resourceType, navigationType);
}
......@@ -20,10 +20,11 @@
#define BLOCKEXTERNALRESOURCESURLINTERCEPTOR_H
#include <WebEngineViewer/NetworkPluginUrlInterceptorInterface>
#include <QWebEngineUrlRequestInfo>
#include "messageviewer_private_export.h"
namespace MessageViewer {
class BlockExternalResourcesUrlInterceptor : public WebEngineViewer::
NetworkPluginUrlInterceptorInterface
class MESSAGEVIEWER_TESTS_EXPORT BlockExternalResourcesUrlInterceptor : public WebEngineViewer::NetworkPluginUrlInterceptorInterface
{
Q_OBJECT
public:
......@@ -33,6 +34,7 @@ public:
Q_REQUIRED_RESULT bool interceptRequest(QWebEngineUrlRequestInfo &info) override;
void setAllowExternalContent(bool b);
Q_REQUIRED_RESULT bool allowExternalContent() const;
Q_REQUIRED_RESULT bool interceptRequest(const QString &scheme, QWebEngineUrlRequestInfo::ResourceType resourceType, QWebEngineUrlRequestInfo::NavigationType navigationType);
Q_SIGNALS:
void formSubmittedForbidden();
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment