tst_qnetworkreply: add a test for http abort.

Change-Id: Iec5fe195ff2befe92e759f77768240728bef31bd
Reviewed-on: http://codereview.qt.nokia.com/302
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Markus Goetz
This commit is contained in:
Martin Petersson 2011-06-01 12:38:34 +02:00 committed by Qt Continuous Integration System
parent 7b6c3707de
commit 1dd7b8ace0

View File

@ -6193,16 +6193,62 @@ void tst_QNetworkReply::synchronousRequestSslFailure()
}
#endif
class HttpAbortHelper : public QObject
{
Q_OBJECT
public:
HttpAbortHelper(QNetworkReply *parent)
: QObject(parent)
{
mReply = parent;
connect(parent, SIGNAL(readyRead()), this, SLOT(readyRead()));
}
~HttpAbortHelper()
{
}
public slots:
void readyRead()
{
mReply->abort();
QMetaObject::invokeMethod(&QTestEventLoop::instance(), "exitLoop", Qt::QueuedConnection);
}
private:
QNetworkReply *mReply;
};
void tst_QNetworkReply::httpAbort()
{
// FIXME: Implement a test that aborts a big HTTP reply
// a) after the first readyRead()
// b) immediatly after the get()
// c) after the finished()
// The goal is no crash and no irrelevant signals after the abort
// FIXME Also implement one where we do a big upload and then abort().
// It must not crash either.
// Abort after the first readyRead()
QNetworkRequest request("http://" + QtNetworkSettings::serverName() + "/qtest/bigfile");
QNetworkReplyPtr reply;
reply = manager.get(request);
HttpAbortHelper replyHolder(reply);
QTestEventLoop::instance().enterLoop(10);
QVERIFY(!QTestEventLoop::instance().timeout());
QCOMPARE(reply->error(), QNetworkReply::OperationCanceledError);
QVERIFY(reply->isFinished());
// Abort immediatly after the get()
QNetworkReplyPtr reply2 = manager.get(request);
connect(reply2, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop()));
reply2->abort();
QCOMPARE(reply2->error(), QNetworkReply::OperationCanceledError);
QVERIFY(reply2->isFinished());
// Abort after the finished()
QNetworkRequest request3("http://" + QtNetworkSettings::serverName() + "/qtest/rfc3252.txt");
QNetworkReplyPtr reply3 = manager.get(request3);
connect(reply3, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop()));
QTestEventLoop::instance().enterLoop(10);
QVERIFY(reply3->isFinished());
reply3->abort();
QCOMPARE(reply3->error(), QNetworkReply::NoError);
}
void tst_QNetworkReply::dontInsertPartialContentIntoTheCache()