Commit 72246d52 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

improve autotest. Clean up

parent 0996f81c
......@@ -39,4 +39,26 @@ void CheckPhishingUrlJobTest::shouldNotBeAbleToStartWithEmptyUrl()
QVERIFY(!job.canStart());
}
void CheckPhishingUrlJobTest::shouldCreateRequest_data()
{
QTest::addColumn<QUrl>("url");
QTest::addColumn<QByteArray>("request");
QTest::addColumn<bool>("canStart");
QTest::newRow("no url") << QUrl() << QByteArray() << false;
QTest::newRow("value") << QUrl(QStringLiteral("http://www.kde.org")) << QByteArray("{\"client\":{\"clientId\":\"KDE\",\"clientVersion\":\"5.4.0\"},\"threatInfo\":{\"platformTypes\":[\"WINDOWS\"],\"threatEntries\":[{\"url\":\"http://www.kde.org\"}],\"threatEntryTypes\":[\"URL\"],\"threatTypes\":[\"MALWARE\"]}}") << true;
}
void CheckPhishingUrlJobTest::shouldCreateRequest()
{
QFETCH(QUrl, url);
QFETCH(QByteArray, request);
QFETCH(bool, canStart);
WebEngineViewer::CheckPhishingUrlJob job;
job.setUrl(url);
QCOMPARE(job.canStart(), canStart);
if (canStart) {
QCOMPARE(job.jsonRequest(), request);
}
}
QTEST_MAIN(CheckPhishingUrlJobTest)
......@@ -30,6 +30,8 @@ public:
~CheckPhishingUrlJobTest();
private Q_SLOTS:
void shouldNotBeAbleToStartWithEmptyUrl();
void shouldCreateRequest_data();
void shouldCreateRequest();
};
#endif // CHECKPHISHINGURLJOBTEST_H
......@@ -41,7 +41,7 @@ CheckPhishingUrlJob::~CheckPhishingUrlJob()
void CheckPhishingUrlJob::slotSslErrors(QNetworkReply *reply, const QList<QSslError> &error)
{
qCDebug(WEBENGINEVIEWER_LOG) << " void StorageServiceAbstractJob::slotSslErrors(QNetworkReply *reply, const QList<QSslError> &error)" << error.count();
qCDebug(WEBENGINEVIEWER_LOG) << " void CheckPhishingUrlJob::slotSslErrors(QNetworkReply *reply, const QList<QSslError> &error)" << error.count();
reply->ignoreSslErrors(error);
}
......@@ -64,7 +64,8 @@ void CheckPhishingUrlJob::parse(const QByteArray &replyStr)
const QVariantList info = answer.value(QStringLiteral("matches")).toList();
if (info.count() == 1) {
const QVariantMap map = info.at(0).toMap();
if (map[QStringLiteral("threatType")] == QStringLiteral("MALWARE")) {
const QString threatTypeStr = map[QStringLiteral("threatType")].toString();
if (threatTypeStr == QStringLiteral("MALWARE")) {
const QVariantMap urlMap = map[QStringLiteral("threat")].toMap();
if (urlMap.count() == 1) {
if (urlMap[QStringLiteral("url")].toString() == mUrl.toString()) {
......@@ -72,7 +73,10 @@ void CheckPhishingUrlJob::parse(const QByteArray &replyStr)
return;
}
}
} else {
qWarning() << " CheckPhishingUrlJob::parse threatTypeStr : " << threatTypeStr;
}
}
Q_EMIT result(WebEngineViewer::CheckPhishingUrlJob::Unknown, mUrl);
}
......@@ -135,7 +139,11 @@ QByteArray CheckPhishingUrlJob::jsonRequest() const
map.insert(QStringLiteral("threatInfo"), threatMap);
const QJsonDocument postData = QJsonDocument::fromVariant(map);
#ifdef DEBUG_JSON_REQUEST
const QByteArray baPostData = postData.toJson();
#else
const QByteArray baPostData = postData.toJson(QJsonDocument::Compact);
#endif
return baPostData;
}
......
......@@ -56,10 +56,10 @@ Q_SIGNALS:
private Q_SLOTS:
void slotSslErrors(QNetworkReply *reply, const QList<QSslError> &error);
private:
QString apiKey() const;
void slotError(QNetworkReply::NetworkError error);
void slotCheckUrlFinished(QNetworkReply *reply);
private:
QString apiKey() const;
QUrl mUrl;
QNetworkAccessManager *mNetworkAccessManager;
};
......
Supports Markdown
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