diff options
author | Martin Petersson <martin.petersson@nokia.com> | 2011-06-01 10:38:34 (GMT) |
---|---|---|
committer | Martin Petersson <martin.petersson@nokia.com> | 2011-06-21 08:54:30 (GMT) |
commit | 16158cd65e16af99bc07bbf2af7a9ee3417ff7a4 (patch) | |
tree | 04c2da6c46b33e474a140369b12d9ee6194277bd /tests/auto/qnetworkreply | |
parent | 9ae35e8c10108c87b2ac10975dbe75651f7cd33e (diff) | |
download | Qt-16158cd65e16af99bc07bbf2af7a9ee3417ff7a4.zip Qt-16158cd65e16af99bc07bbf2af7a9ee3417ff7a4.tar.gz Qt-16158cd65e16af99bc07bbf2af7a9ee3417ff7a4.tar.bz2 |
tst_qnetworkreply: add a test for http abort.
Change-Id: Iec5fe195ff2befe92e759f77768240728bef31bd
(cherry picked from commit 752d807797a0021e412a20b0a8fcc34b4fd8e380)
Diffstat (limited to 'tests/auto/qnetworkreply')
-rw-r--r-- | tests/auto/qnetworkreply/tst_qnetworkreply.cpp | 58 |
1 files changed, 52 insertions, 6 deletions
diff --git a/tests/auto/qnetworkreply/tst_qnetworkreply.cpp b/tests/auto/qnetworkreply/tst_qnetworkreply.cpp index 25925bd..45f501c 100644 --- a/tests/auto/qnetworkreply/tst_qnetworkreply.cpp +++ b/tests/auto/qnetworkreply/tst_qnetworkreply.cpp @@ -6195,16 +6195,62 @@ void tst_QNetworkReply::synchronousRequestSslFailure() } #endif -void tst_QNetworkReply::httpAbort() +class HttpAbortHelper : public QObject { - // 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 + 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 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() |