summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMontel Laurent <montel@kde.org>2016-11-20 12:47:28 (GMT)
committerMontel Laurent <montel@kde.org>2016-11-20 12:47:28 (GMT)
commitbac3d30cf261ac45f2503d930412c8d39ebe4012 (patch)
treeb86b865acb9f60f45fea03e96058ae8b441d3846
parentd733c0cd61e390f4e5e6a2192fa63466cb57b926 (diff)
Improve autotests
-rw-r--r--webengineviewer/src/checkphishingurl/autotests/searchfullhashjobtest.cpp33
-rw-r--r--webengineviewer/src/checkphishingurl/autotests/searchfullhashjobtest.h5
-rw-r--r--webengineviewer/src/checkphishingurl/searchfullhashjob.cpp2
3 files changed, 39 insertions, 1 deletions
diff --git a/webengineviewer/src/checkphishingurl/autotests/searchfullhashjobtest.cpp b/webengineviewer/src/checkphishingurl/autotests/searchfullhashjobtest.cpp
index dbb7aeb..bae3e58 100644
--- a/webengineviewer/src/checkphishingurl/autotests/searchfullhashjobtest.cpp
+++ b/webengineviewer/src/checkphishingurl/autotests/searchfullhashjobtest.cpp
@@ -18,6 +18,7 @@
*/
#include "searchfullhashjobtest.h"
+#include "../searchfullhashjob.h"
#include <QTest>
SearchFullHashJobTest::SearchFullHashJobTest(QObject *parent)
@@ -31,4 +32,36 @@ SearchFullHashJobTest::~SearchFullHashJobTest()
}
+void SearchFullHashJobTest::shouldNotBeAbleToStartWithEmptyUrl()
+{
+ WebEngineViewer::SearchFullHashJob job;
+ QVERIFY(!job.canStart());
+}
+
+void SearchFullHashJobTest::shouldCreateRequest_data()
+{
+ QTest::addColumn<QByteArray>("hash");
+ QTest::addColumn<QString>("databaseHash");
+ QTest::addColumn<QByteArray>("request");
+ QTest::addColumn<bool>("canStart");
+ QTest::newRow("no hash") << QByteArray() << QString() << 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 SearchFullHashJobTest::shouldCreateRequest()
+{
+ QFETCH(QByteArray, hash);
+ QFETCH(QString, databaseHash);
+ QFETCH(QByteArray, request);
+ QFETCH(bool, canStart);
+ WebEngineViewer::SearchFullHashJob job;
+ job.setDatabaseState(databaseHash);
+ job.setSearchHash(hash);
+ QCOMPARE(job.canStart(), canStart);
+ if (canStart) {
+ QCOMPARE(job.jsonRequest(), request);
+ }
+}
+
+
QTEST_MAIN(SearchFullHashJobTest)
diff --git a/webengineviewer/src/checkphishingurl/autotests/searchfullhashjobtest.h b/webengineviewer/src/checkphishingurl/autotests/searchfullhashjobtest.h
index fa63705..d17d792 100644
--- a/webengineviewer/src/checkphishingurl/autotests/searchfullhashjobtest.h
+++ b/webengineviewer/src/checkphishingurl/autotests/searchfullhashjobtest.h
@@ -28,6 +28,11 @@ class SearchFullHashJobTest : public QObject
public:
explicit SearchFullHashJobTest(QObject *parent = Q_NULLPTR);
~SearchFullHashJobTest();
+
+private Q_SLOTS:
+ void shouldNotBeAbleToStartWithEmptyUrl();
+ void shouldCreateRequest_data();
+ void shouldCreateRequest();
};
#endif // SEARCHFULLHASHJOBTEST_H
diff --git a/webengineviewer/src/checkphishingurl/searchfullhashjob.cpp b/webengineviewer/src/checkphishingurl/searchfullhashjob.cpp
index 495149d..d37c98e 100644
--- a/webengineviewer/src/checkphishingurl/searchfullhashjob.cpp
+++ b/webengineviewer/src/checkphishingurl/searchfullhashjob.cpp
@@ -219,7 +219,7 @@ void SearchFullHashJob::slotError(QNetworkReply::NetworkError error)
bool SearchFullHashJob::canStart() const
{
- return !mHash.isEmpty();
+ return !mHash.isEmpty() && !mDatabaseHash.isEmpty();
}
void SearchFullHashJob::setDatabaseState(const QString &hash)