From 89a26ec7ecb758b635087899418eeb703138c482 Mon Sep 17 00:00:00 2001 From: Harald Fernengel Date: Fri, 5 Nov 2010 13:22:20 +0100 Subject: Hide the cursor in the tested text edit Hiding the cursor will make the image comparison more robust. This fixes the sporadic test fail we saw on some machines - every time the blinking cursor was visible, the test failed. Reviewed-by: Robert Griebl --- tests/auto/qtextedit/tst_qtextedit.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/auto/qtextedit/tst_qtextedit.cpp b/tests/auto/qtextedit/tst_qtextedit.cpp index 321aa22..d1832d8 100644 --- a/tests/auto/qtextedit/tst_qtextedit.cpp +++ b/tests/auto/qtextedit/tst_qtextedit.cpp @@ -2163,6 +2163,9 @@ void tst_QTextEdit::noWrapBackgrounds() QTextEdit edit; edit.setLineWrapMode(QTextEdit::NoWrap); + // hide the cursor in order to make the image comparison below reliable + edit.setCursorWidth(0); + QTextFrame *root = edit.document()->rootFrame(); QTextFrameFormat frameFormat = root->frameFormat(); frameFormat.setLeftMargin(2); @@ -2178,8 +2181,6 @@ void tst_QTextEdit::noWrapBackgrounds() layout->addWidget(&edit); topLevel.show(); - QTest::qWait(1000); - QImage img = QPixmap::grabWidget(edit.viewport()).toImage(); QCOMPARE(img, img.mirrored(true, false)); } -- cgit v0.12 From d4cad3c2f3fdbf6a1bda926582fb8ad4b6f08666 Mon Sep 17 00:00:00 2001 From: Markus Goetz Date: Fri, 5 Nov 2010 14:11:30 +0100 Subject: tst_qnetworkreply: One more HTTP test using setReadBufferSize() Task-number: QTBUG-13431 --- tests/auto/qnetworkreply/tst_qnetworkreply.cpp | 52 ++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/tests/auto/qnetworkreply/tst_qnetworkreply.cpp b/tests/auto/qnetworkreply/tst_qnetworkreply.cpp index d21428b..bef1e7e6 100644 --- a/tests/auto/qnetworkreply/tst_qnetworkreply.cpp +++ b/tests/auto/qnetworkreply/tst_qnetworkreply.cpp @@ -297,6 +297,8 @@ private Q_SLOTS: void qtbug4121unknownAuthentication(); + void qtbug13431replyThrottling(); + // NOTE: This test must be last! void parentingRepliesToTheApp(); }; @@ -4643,6 +4645,56 @@ void tst_QNetworkReply::qtbug4121unknownAuthentication() QCOMPARE(reply->error(), QNetworkReply::AuthenticationRequiredError); } +class QtBug13431Helper : public QObject { + Q_OBJECT +public: + QNetworkReply* m_reply; + QTimer m_dlTimer; +public slots: + void replyFinished(QNetworkReply*) { + QTestEventLoop::instance().exitLoop(); + } + + void onReadAndReschedule() { + const qint64 bytesReceived = m_reply->bytesAvailable(); + if (bytesReceived) { + QByteArray data = m_reply->read(bytesReceived); + // reschedule read + const int millisecDelay = static_cast(bytesReceived * 1000 / m_reply->readBufferSize()); + m_dlTimer.start(millisecDelay); + } + else { + // reschedule read + m_dlTimer.start(200); + } + } +}; + +void tst_QNetworkReply::qtbug13431replyThrottling() +{ + QtBug13431Helper helper; + + QNetworkAccessManager nam; + connect(&nam, SIGNAL(finished(QNetworkReply*)), &helper, SLOT(replyFinished(QNetworkReply*))); + + // Download a bigger file + QNetworkRequest netRequest(QUrl("http://qt-test-server/qtest/bigfile")); + helper.m_reply = nam.get(netRequest); + // Set the throttle + helper.m_reply->setReadBufferSize(36000); + + // Schedule a timer that tries to read + + connect(&helper.m_dlTimer, SIGNAL(timeout()), &helper, SLOT(onReadAndReschedule())); + helper.m_dlTimer.setSingleShot(true); + helper.m_dlTimer.start(0); + + QTestEventLoop::instance().enterLoop(30); + QVERIFY(!QTestEventLoop::instance().timeout()); + QVERIFY(helper.m_reply->isFinished()); + QCOMPARE(helper.m_reply->error(), QNetworkReply::NoError); +} + // NOTE: This test must be last testcase in tst_qnetworkreply! -- cgit v0.12 From 74d593de47d264e2bfa77f01df4af540f9462c19 Mon Sep 17 00:00:00 2001 From: Markus Goetz Date: Fri, 5 Nov 2010 15:03:06 +0100 Subject: tst_qnetworkreply: New HTTP test with AuthenticationReuseAttribute --- tests/auto/qnetworkreply/tst_qnetworkreply.cpp | 29 ++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/tests/auto/qnetworkreply/tst_qnetworkreply.cpp b/tests/auto/qnetworkreply/tst_qnetworkreply.cpp index bef1e7e6..a986438 100644 --- a/tests/auto/qnetworkreply/tst_qnetworkreply.cpp +++ b/tests/auto/qnetworkreply/tst_qnetworkreply.cpp @@ -299,6 +299,8 @@ private Q_SLOTS: void qtbug13431replyThrottling(); + void httpWithNoCredentialUsage(); + // NOTE: This test must be last! void parentingRepliesToTheApp(); }; @@ -4695,6 +4697,33 @@ void tst_QNetworkReply::qtbug13431replyThrottling() QCOMPARE(helper.m_reply->error(), QNetworkReply::NoError); } +void tst_QNetworkReply::httpWithNoCredentialUsage() +{ + QNetworkRequest request(QUrl("http://httptest:httptest@" + QtNetworkSettings::serverName() + "/qtest/protected/cgi-bin/md5sum.cgi")); + // Do not use credentials + request.setAttribute(QNetworkRequest::AuthenticationReuseAttribute, QNetworkRequest::Manual); + QNetworkAccessManager manager; + QNetworkReplyPtr reply = manager.get(request); + + qRegisterMetaType("QNetworkReply*"); + qRegisterMetaType("QAuthenticator*"); + QSignalSpy authSpy(&manager, SIGNAL(authenticationRequired(QNetworkReply*,QAuthenticator*))); + QSignalSpy finishedSpy(&manager, SIGNAL(finished(QNetworkReply*))); + qRegisterMetaType("QNetworkReply::NetworkError"); + QSignalSpy errorSpy(reply, SIGNAL(error(QNetworkReply::NetworkError))); + + connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop()), Qt::QueuedConnection); + QTestEventLoop::instance().enterLoop(10); + QVERIFY(!QTestEventLoop::instance().timeout()); + + // We check if authenticationRequired was emitted, however we do not anything in it so it should be 401 + QCOMPARE(authSpy.count(), 1); + QCOMPARE(finishedSpy.count(), 1); + QCOMPARE(errorSpy.count(), 1); + + QCOMPARE(reply->error(), QNetworkReply::AuthenticationRequiredError); +} + // NOTE: This test must be last testcase in tst_qnetworkreply! -- cgit v0.12