Commit ffc72526 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Add autotest

parent b405f14f
......@@ -21,3 +21,9 @@ ecm_add_test(webengineexporthtmlpagejobtest.cpp ${testwebengineviewer_webengine_
NAME_PREFIX "webengineviewer-"
LINK_LIBRARIES Qt5::Test KF5::WebEngineViewer
)
ecm_add_test(webengineexportpdfpagejobtest.cpp ${testwebengineviewer_webengine_SRCS}
TEST_NAME webengineexportpdfpagejobtest
NAME_PREFIX "webengineviewer-"
LINK_LIBRARIES Qt5::Test KF5::WebEngineViewer
)
/*
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 "webengineexportpdfpagejobtest.h"
#include "webengineexportpdfpagejob.h"
#include <QSignalSpy>
#include <QTest>
#include <QWebEngineView>
QTEST_MAIN(WebEngineExportPdfPageJobTest)
WebEngineExportPdfPageJobTest::WebEngineExportPdfPageJobTest(QObject *parent)
: QObject(parent)
{
}
void WebEngineExportPdfPageJobTest::shouldHaveDefaultValue()
{
WebEngineViewer::WebEngineExportPdfPageJob job;
QVERIFY(!job.engineView());
QVERIFY(job.pdfPath().isEmpty());
QVERIFY(!job.canStart());
}
void WebEngineExportPdfPageJobTest::shouldBeAbleToExport()
{
WebEngineViewer::WebEngineExportPdfPageJob job;
QVERIFY(!job.canStart());
job.setPdfPath(QStringLiteral("foo"));
QVERIFY(!job.canStart());
QWebEngineView *webEngine = new QWebEngineView;
job.setEngineView(webEngine);
QVERIFY(job.canStart());
delete webEngine;
}
void WebEngineExportPdfPageJobTest::shouldEmitSignalFailed()
{
WebEngineViewer::WebEngineExportPdfPageJob job;
QSignalSpy spyFailed(&job, &WebEngineViewer::WebEngineExportPdfPageJob::exportPdfFailed);
QSignalSpy spySuccess(&job, &WebEngineViewer::WebEngineExportPdfPageJob::exportToPdfSuccess);
QVERIFY(!job.engineView());
job.start();
QCOMPARE(spyFailed.count(), 1);
QCOMPARE(spySuccess.count(), 0);
}
void WebEngineExportPdfPageJobTest::shouldEmitSignalSuccess()
{
WebEngineViewer::WebEngineExportPdfPageJob job;
QSignalSpy spyFailed(&job, &WebEngineViewer::WebEngineExportPdfPageJob::exportPdfFailed);
QSignalSpy spySuccess(&job, &WebEngineViewer::WebEngineExportPdfPageJob::exportToPdfSuccess);
job.setPdfPath(QDir::tempPath() + QStringLiteral("/test-webengine-export-test.pdf"));
QWebEngineView *webEngine = new QWebEngineView;
job.setEngineView(webEngine);
job.start();
QVERIFY(spySuccess.wait());
QCOMPARE(spyFailed.count(), 0);
QCOMPARE(spySuccess.count(), 1);
delete webEngine;
}
/*
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 WEBENGINEEXPORTPDFPAGEJOBTEST_H
#define WEBENGINEEXPORTPDFPAGEJOBTEST_H
#include <QObject>
class WebEngineExportPdfPageJobTest : public QObject
{
Q_OBJECT
public:
explicit WebEngineExportPdfPageJobTest(QObject *parent = nullptr);
~WebEngineExportPdfPageJobTest() = default;
private Q_SLOTS:
void shouldHaveDefaultValue();
void shouldBeAbleToExport();
void shouldEmitSignalFailed();
void shouldEmitSignalSuccess();
};
#endif // WEBENGINEEXPORTPDFPAGEJOBTEST_H
......@@ -37,6 +37,7 @@ void WebEngineExportPdfPageJob::start()
{
if (!canStart()) {
qCWarning(WEBENGINEVIEWER_LOG) << "webengineview not defined or path is not defined.! It's a bug";
Q_EMIT exportPdfFailed();
deleteLater();
return;
}
......
......@@ -34,13 +34,7 @@ class WebEngineViewer::WebEngineViewPrivate
{
public:
explicit WebEngineViewPrivate(WebEngineView *q)
: mSavedRelativePosition(-1)
, mCurrentWidget(nullptr)
, mWebEngineNavigatorInterceptor(nullptr)
, mWebEngineNavigatorInterceptorView(nullptr)
, mPhishingDatabase(nullptr)
, mCrashCount(0)
, q(q)
: q(q)
{
}
......@@ -78,13 +72,13 @@ public:
}
}
qreal mSavedRelativePosition;
qreal mSavedRelativePosition = -1;
QWidget *mCurrentWidget = nullptr;
WebEngineManageScript *mManagerScript = nullptr;
WebEngineNavigationRequestInterceptor *mWebEngineNavigatorInterceptor = nullptr;
WebEngineView *mWebEngineNavigatorInterceptorView = nullptr;
LocalDataBaseManager *mPhishingDatabase = nullptr;
int mCrashCount;
int mCrashCount = 0;
private:
WebEngineView *const q;
......
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