summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorShane Kearns <shane.kearns@accenture.com>2011-10-03 16:29:43 +0100
committerQt by Nokia <qt-info@nokia.com>2011-10-06 11:24:20 +0200
commitcb2e618127d881bec0dec57ae175a2a066a6d67a (patch)
tree319eb1b78eaba893a5a9a859cb3767ba9c4ba10e /tests
parentd3ef64261484ef1e750671263429810918ca6954 (diff)
Create auto test for http HEAD request
This is in order to have a regression test for QT-5304. However the test is also checking basic functionality of head requests too. Task-Number: QT-5304 Change-Id: I0d98bd1f1125ffd49d9f3c859a51b2aaee95379a Reviewed-By: Martin Petersson Reviewed-on: http://codereview.qt-project.org/6033 Reviewed-by: Martin Petersson <Martin.Petersson@nokia.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/network/access/qnetworkreply/.gitattributes1
-rw-r--r--tests/auto/network/access/qnetworkreply/index.html3
-rw-r--r--tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp61
3 files changed, 65 insertions, 0 deletions
diff --git a/tests/auto/network/access/qnetworkreply/.gitattributes b/tests/auto/network/access/qnetworkreply/.gitattributes
index 80252cfd34..7fa30e3f99 100644
--- a/tests/auto/network/access/qnetworkreply/.gitattributes
+++ b/tests/auto/network/access/qnetworkreply/.gitattributes
@@ -1,3 +1,4 @@
rfc3252.txt -crlf
bigfile -crlf
resource -crlf
+index.html -crlf
diff --git a/tests/auto/network/access/qnetworkreply/index.html b/tests/auto/network/access/qnetworkreply/index.html
new file mode 100644
index 0000000000..0ce7b5b8a5
--- /dev/null
+++ b/tests/auto/network/access/qnetworkreply/index.html
@@ -0,0 +1,3 @@
+<h1>Welcome to qt-test-server</h1>
+<img src="gif/fluke.gif" alt="fluke">
+<p>This is a network test server. It serves as a cacheing ftp and http proxy, transparent http/socks5 proxy, imap, ftp and http server, plus more.</p>
diff --git a/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp b/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp
index bc7ab7f24a..4d4aca6517 100644
--- a/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp
+++ b/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp
@@ -193,6 +193,8 @@ private Q_SLOTS:
void getFromHttp();
void getErrors_data();
void getErrors();
+ void headFromHttp_data();
+ void headFromHttp();
void putToFile_data();
void putToFile();
void putToFtp_data();
@@ -1601,6 +1603,65 @@ void tst_QNetworkReply::getFromHttp()
QCOMPARE(reply->readAll(), reference.readAll());
}
+void tst_QNetworkReply::headFromHttp_data()
+{
+ QTest::addColumn<qint64>("referenceSize");
+ QTest::addColumn<QUrl>("url");
+ QTest::addColumn<QString>("contentType");
+ QTest::addColumn<QNetworkProxy>("proxy");
+
+ qint64 rfcsize = QFileInfo(SRCDIR "/rfc3252.txt").size();
+ qint64 bigfilesize = QFileInfo(SRCDIR "/bigfile").size();
+ qint64 indexsize = QFileInfo(SRCDIR "/index.html").size();
+
+ //testing proxies, mainly for the 407 response from http proxy
+ for (int i = 0; i < proxies.count(); ++i) {
+ QTest::newRow("rfc" + proxies.at(i).tag) << rfcsize << QUrl("http://" + QtNetworkSettings::serverName() + "/qtest/rfc3252.txt") << "text/plain" << proxies.at(i).proxy;
+ QTest::newRow("bigfile" + proxies.at(i).tag) << bigfilesize << QUrl("http://" + QtNetworkSettings::serverName() + "/qtest/bigfile") << "text/plain" << proxies.at(i).proxy;
+ QTest::newRow("index" + proxies.at(i).tag) << indexsize << QUrl("http://" + QtNetworkSettings::serverName() + "/qtest/") << "text/html" << proxies.at(i).proxy;
+ QTest::newRow("with-authentication" + proxies.at(i).tag) << rfcsize << QUrl("http://" + QtNetworkSettings::serverName() + "/qtest/rfcs-auth/rfc3252.txt") << "text/plain" << proxies.at(i).proxy;
+ QTest::newRow("cgi" + proxies.at(i).tag) << (qint64)-1 << QUrl("http://qt-test-server/qtest/cgi-bin/httpcachetest_expires500.cgi") << "text/html" << proxies.at(i).proxy;
+ }
+}
+
+void tst_QNetworkReply::headFromHttp()
+{
+ QFETCH(qint64, referenceSize);
+ QFETCH(QUrl, url);
+ QFETCH(QString, contentType);
+ QFETCH(QNetworkProxy, proxy);
+
+ QNetworkRequest request(url);
+ QNetworkReplyPtr reply;
+
+ QElapsedTimer time;
+ time.start();
+
+ manager.setProxy(proxy);
+ connect(&manager, SIGNAL(authenticationRequired(QNetworkReply*,QAuthenticator*)),
+ SLOT(authenticationRequired(QNetworkReply*,QAuthenticator*)));
+ connect(&manager, SIGNAL(proxyAuthenticationRequired(QNetworkProxy,QAuthenticator*)),
+ SLOT(proxyAuthenticationRequired(QNetworkProxy,QAuthenticator*)));
+
+ RUN_REQUEST(runSimpleRequest(QNetworkAccessManager::HeadOperation, request, reply));
+
+ manager.disconnect(SIGNAL(authenticationRequired(QNetworkReply*,QAuthenticator*)),
+ this, SLOT(authenticationRequired(QNetworkReply*,QAuthenticator*)));
+ manager.disconnect(SIGNAL(proxyAuthenticationRequired(QNetworkProxy,QAuthenticator*)),
+ this, SLOT(proxyAuthenticationRequired(QNetworkProxy,QAuthenticator*)));
+
+ QVERIFY(time.elapsed() < 8000); //check authentication didn't wait for the server to timeout the http connection (15s on qt test server)
+
+ QCOMPARE(reply->url(), request.url());
+ QCOMPARE(reply->error(), QNetworkReply::NoError);
+ QCOMPARE(reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(), 200);
+ // only compare when the header is set.
+ if (reply->header(QNetworkRequest::ContentLengthHeader).isValid() && referenceSize >= 0)
+ QCOMPARE(reply->header(QNetworkRequest::ContentLengthHeader).toLongLong(), referenceSize);
+ if (reply->header(QNetworkRequest::ContentTypeHeader).isValid())
+ QCOMPARE(reply->header(QNetworkRequest::ContentTypeHeader).toString(), contentType);
+}
+
void tst_QNetworkReply::getErrors_data()
{
QTest::addColumn<QString>("url");