summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMontel Laurent <montel@kde.org>2016-11-08 12:38:48 (GMT)
committerMontel Laurent <montel@kde.org>2016-11-08 12:38:59 (GMT)
commit72246d52b1fd5add44ca8c56f762560577b9e396 (patch)
tree93a95b5de37e36dd291fbea41a3c840b77a871ea
parent0996f81c43f704cab95f0b49042497b1be8631d2 (diff)
improve autotest. Clean up
-rw-r--r--webengineviewer/src/checkphishingurl/autotests/checkphishingurljobtest.cpp22
-rw-r--r--webengineviewer/src/checkphishingurl/autotests/checkphishingurljobtest.h2
-rw-r--r--webengineviewer/src/checkphishingurl/checkphishingurljob.cpp12
-rw-r--r--webengineviewer/src/checkphishingurl/checkphishingurljob.h4
4 files changed, 36 insertions, 4 deletions
diff --git a/webengineviewer/src/checkphishingurl/autotests/checkphishingurljobtest.cpp b/webengineviewer/src/checkphishingurl/autotests/checkphishingurljobtest.cpp
index 60e3b10..c6ce53f 100644
--- a/webengineviewer/src/checkphishingurl/autotests/checkphishingurljobtest.cpp
+++ b/webengineviewer/src/checkphishingurl/autotests/checkphishingurljobtest.cpp
@@ -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)
diff --git a/webengineviewer/src/checkphishingurl/autotests/checkphishingurljobtest.h b/webengineviewer/src/checkphishingurl/autotests/checkphishingurljobtest.h
index 61fd206..85dbe08 100644
--- a/webengineviewer/src/checkphishingurl/autotests/checkphishingurljobtest.h
+++ b/webengineviewer/src/checkphishingurl/autotests/checkphishingurljobtest.h
@@ -30,6 +30,8 @@ public:
~CheckPhishingUrlJobTest();
private Q_SLOTS:
void shouldNotBeAbleToStartWithEmptyUrl();
+ void shouldCreateRequest_data();
+ void shouldCreateRequest();
};
#endif // CHECKPHISHINGURLJOBTEST_H
diff --git a/webengineviewer/src/checkphishingurl/checkphishingurljob.cpp b/webengineviewer/src/checkphishingurl/checkphishingurljob.cpp
index 331a125..0128c9b 100644
--- a/webengineviewer/src/checkphishingurl/checkphishingurljob.cpp
+++ b/webengineviewer/src/checkphishingurl/checkphishingurljob.cpp
@@ -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;
}
diff --git a/webengineviewer/src/checkphishingurl/checkphishingurljob.h b/webengineviewer/src/checkphishingurl/checkphishingurljob.h
index 9eefd39..fd3df5e 100644
--- a/webengineviewer/src/checkphishingurl/checkphishingurljob.h
+++ b/webengineviewer/src/checkphishingurl/checkphishingurljob.h
@@ -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;
};