summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMontel Laurent <montel@kde.org>2016-11-16 12:55:20 (GMT)
committerMontel Laurent <montel@kde.org>2016-11-16 12:55:20 (GMT)
commit3765adbcf236cd76c33889c8632e6dab8aead4ac (patch)
treec303ff28bfce0dda11f50d4f10b4287a12a2b9ac
parentb19c6ed8d760ef9c6a2b8eaff1fa95798d22e9f5 (diff)
Improve autotest
-rw-r--r--webengineviewer/src/checkphishingurl/checkphishingurljob.cpp15
-rw-r--r--webengineviewer/src/checkphishingurl/checkphishingurljob.h3
-rw-r--r--webengineviewer/src/checkphishingurl/tests/checkphishingurlgui.cpp1
3 files changed, 12 insertions, 7 deletions
diff --git a/webengineviewer/src/checkphishingurl/checkphishingurljob.cpp b/webengineviewer/src/checkphishingurl/checkphishingurljob.cpp
index d5b0c9d..393de59 100644
--- a/webengineviewer/src/checkphishingurl/checkphishingurljob.cpp
+++ b/webengineviewer/src/checkphishingurl/checkphishingurljob.cpp
@@ -24,11 +24,11 @@
#include <QJsonDocument>
#include <webengineviewer_debug.h>
-//#define DEBUG_JSON_REQUEST 1
using namespace WebEngineViewer;
CheckPhishingUrlJob::CheckPhishingUrlJob(QObject *parent)
- : QObject(parent)
+ : QObject(parent),
+ mUseCompactJson(true)
{
mNetworkAccessManager = new QNetworkAccessManager(this);
connect(mNetworkAccessManager, &QNetworkAccessManager::finished, this, &CheckPhishingUrlJob::slotCheckUrlFinished);
@@ -50,6 +50,11 @@ QString CheckPhishingUrlJob::apiKey() const
return QStringLiteral("AIzaSyBS62pXATjabbH2RM_jO2EzDg1mTMHlnyo");
}
+void CheckPhishingUrlJob::setUseCompactJson(bool useCompactJson)
+{
+ mUseCompactJson = useCompactJson;
+}
+
void CheckPhishingUrlJob::parse(const QByteArray &replyStr)
{
QJsonDocument document = QJsonDocument::fromJson(replyStr);
@@ -120,11 +125,7 @@ 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
+ const QByteArray baPostData = postData.toJson(mUseCompactJson ? QJsonDocument::Compact : QJsonDocument::Indented);
return baPostData;
}
diff --git a/webengineviewer/src/checkphishingurl/checkphishingurljob.h b/webengineviewer/src/checkphishingurl/checkphishingurljob.h
index fd3df5e..83d941b 100644
--- a/webengineviewer/src/checkphishingurl/checkphishingurljob.h
+++ b/webengineviewer/src/checkphishingurl/checkphishingurljob.h
@@ -50,6 +50,8 @@ public:
QByteArray jsonRequest() const;
void parse(const QByteArray &replyStr);
+ void setUseCompactJson(bool useCompactJson);
+
Q_SIGNALS:
void result(WebEngineViewer::CheckPhishingUrlJob::UrlStatus status, const QUrl &url);
void debugJson(const QByteArray &ba);
@@ -61,6 +63,7 @@ private Q_SLOTS:
private:
QString apiKey() const;
QUrl mUrl;
+ bool mUseCompactJson;
QNetworkAccessManager *mNetworkAccessManager;
};
}
diff --git a/webengineviewer/src/checkphishingurl/tests/checkphishingurlgui.cpp b/webengineviewer/src/checkphishingurl/tests/checkphishingurlgui.cpp
index cfb2562..4f304ec 100644
--- a/webengineviewer/src/checkphishingurl/tests/checkphishingurlgui.cpp
+++ b/webengineviewer/src/checkphishingurl/tests/checkphishingurlgui.cpp
@@ -69,6 +69,7 @@ void CheckPhishingUrlGui::slotCheckUrl()
mResult->clear();
WebEngineViewer::CheckPhishingUrlJob *job = new WebEngineViewer::CheckPhishingUrlJob(this);
+ job->setUseCompactJson(false);
connect(job, &WebEngineViewer::CheckPhishingUrlJob::result, this, &CheckPhishingUrlGui::slotGetResult);
connect(job, &WebEngineViewer::CheckPhishingUrlJob::debugJson, this, &CheckPhishingUrlGui::slotJSonDebug);
job->setUrl(QUrl::fromUserInput(urlStr));