diff options
author | Liang Qi <liang.qi@qt.io> | 2017-11-21 14:34:31 +0100 |
---|---|---|
committer | Liang Qi <liang.qi@qt.io> | 2017-11-23 09:36:03 +0100 |
commit | 153e8b49adfe210cb00490284a14c94c08e03c3f (patch) | |
tree | 59d9522d6dc96215cc2cb1d19b3e8a0e580bcb41 /tests/auto/network/access | |
parent | ef7c0594bf9e41813c9c841e00c3a52269d363f5 (diff) | |
parent | a4113d0c644edba1c39d9d268a259e95ae51c61e (diff) |
Merge remote-tracking branch 'origin/5.10' into dev
Conflicts:
src/network/access/qhttp2protocolhandler_p.h
src/network/kernel/kernel.pri
src/network/ssl/qsslkey_qt.cpp
src/plugins/platforms/cocoa/qcocoascreen.mm
src/plugins/platforms/windows/accessible/iaccessible2.cpp
src/plugins/platforms/windows/accessible/iaccessible2.h
src/plugins/platforms/windows/accessible/qwindowsaccessibility.cpp
src/plugins/platforms/windows/accessible/qwindowsmsaaaccessible.cpp
src/plugins/platforms/windows/accessible/qwindowsmsaaaccessible.h
src/widgets/widgets/qmenu_p.h
tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp
tests/auto/other/qaccessibility/tst_qaccessibility.cpp
tests/auto/testlib/selftests/expected_cmptest.lightxml
tests/auto/testlib/selftests/expected_cmptest.teamcity
tests/auto/testlib/selftests/expected_cmptest.txt
tests/auto/testlib/selftests/expected_cmptest.xml
Done-with: Edward Welbourne <edward.welbourne@qt.io>
Change-Id: I4217cc7d840cbae3e3dd28574741544469c4c6b9
Diffstat (limited to 'tests/auto/network/access')
7 files changed, 173 insertions, 37 deletions
diff --git a/tests/auto/network/access/hpack/tst_hpack.cpp b/tests/auto/network/access/hpack/tst_hpack.cpp index bd337c9f5f..810745a065 100644 --- a/tests/auto/network/access/hpack/tst_hpack.cpp +++ b/tests/auto/network/access/hpack/tst_hpack.cpp @@ -273,13 +273,13 @@ void tst_Hpack::bitstreamCompression() std::vector<uchar> buffer; BitOStream out(buffer); for (unsigned i = 0; i < nValues; ++i) { - const bool isString = std::rand() % 1000 > 500; + const bool isString = QRandomGenerator::global()->bounded(1000) > 500; isA.push_back(isString); if (!isString) { - integers.push_back(std::rand() % 1000); + integers.push_back(QRandomGenerator::global()->bounded(1000u)); out.write(integers.back()); } else { - const auto start = std::rand() % (bytes.length() / 2); + const auto start = QRandomGenerator::global()->bounded(uint(bytes.length()) / 2); auto end = start * 2; if (!end) end = bytes.length() / 2; @@ -287,7 +287,7 @@ void tst_Hpack::bitstreamCompression() const auto &s = strings.back(); totalStringBytes += s.size(); QByteArray data(s.c_str(), int(s.size())); - const bool compressed(std::rand() % 1000 > 500); + const bool compressed(QRandomGenerator::global()->bounded(1000) > 500); out.write(data, compressed); } } @@ -442,8 +442,8 @@ void tst_Hpack::lookupTableDynamic() // Strings are repeating way too often, I want to // have at least some items really evicted and not found, // therefore these weird dances with start/len. - const quint32 start = std::rand() % (dataSize - 10); - quint32 len = std::rand() % (dataSize - start); + const quint32 start = QRandomGenerator::global()->bounded(dataSize - 10); + quint32 len = QRandomGenerator::global()->bounded(dataSize - start); if (!len) len = 1; diff --git a/tests/auto/network/access/http2/tst_http2.cpp b/tests/auto/network/access/http2/tst_http2.cpp index 7b453ca635..51e1849512 100644 --- a/tests/auto/network/access/http2/tst_http2.cpp +++ b/tests/auto/network/access/http2/tst_http2.cpp @@ -224,7 +224,7 @@ void tst_Http2::multipleRequests() }; for (int i = 0; i < nRequests; ++i) - sendRequest(i, priorities[std::rand() % 3]); + sendRequest(i, priorities[QRandomGenerator::global()->bounded(3)]); runEventLoop(); diff --git a/tests/auto/network/access/qftp/tst_qftp.cpp b/tests/auto/network/access/qftp/tst_qftp.cpp index fba0508f04..4bc43f068c 100644 --- a/tests/auto/network/access/qftp/tst_qftp.cpp +++ b/tests/auto/network/access/qftp/tst_qftp.cpp @@ -276,8 +276,7 @@ void tst_QFtp::init() inFileDirExistsFunction = false; - srand(time(0)); - uniqueExtension = QString::number((quintptr)this) + QString::number(rand()) + uniqueExtension = QString::number((quintptr)this) + QString::number(QRandomGenerator::global()->generate()) + QString::number((qulonglong)time(0)); } diff --git a/tests/auto/network/access/qnetworkdiskcache/tst_qnetworkdiskcache.cpp b/tests/auto/network/access/qnetworkdiskcache/tst_qnetworkdiskcache.cpp index e996347a9a..856033fb63 100644 --- a/tests/auto/network/access/qnetworkdiskcache/tst_qnetworkdiskcache.cpp +++ b/tests/auto/network/access/qnetworkdiskcache/tst_qnetworkdiskcache.cpp @@ -30,6 +30,7 @@ #include <QtTest/QtTest> #include <QtNetwork/QtNetwork> #include <qnetworkdiskcache.h> +#include <qrandom.h> #include <algorithm> @@ -693,25 +694,25 @@ public: if (write) { QNetworkCacheMetaData m; - if (qrand() % 2 == 0) + if (QRandomGenerator::global()->bounded(2) == 0) m = metaData; else m = metaData2; - if (qrand() % 20 == 1) { + if (QRandomGenerator::global()->bounded(20) == 1) { //qDebug() << "write update"; cache.updateMetaData(m); continue; } QIODevice *device = cache.prepare(m); - if (qrand() % 20 == 1) { + if (QRandomGenerator::global()->bounded(20) == 1) { //qDebug() << "write remove"; cache.remove(url); continue; } QVERIFY(device); - if (qrand() % 2 == 0) + if (QRandomGenerator::global()->bounded(2) == 0) device->write(longString); else device->write(longString2); @@ -740,9 +741,9 @@ public: delete d; } } - if (qrand() % 5 == 1) + if (QRandomGenerator::global()->bounded(5) == 1) cache.remove(url); - if (qrand() % 5 == 1) + if (QRandomGenerator::global()->bounded(5) == 1) cache.clear(); sleep(0); } @@ -791,7 +792,6 @@ void tst_QNetworkDiskCache::sync() return; QTime midnight(0, 0, 0); - qsrand(midnight.secsTo(QTime::currentTime())); Runner reader(tempDir.path()); reader.dt = QDateTime::currentDateTime(); reader.write = false; diff --git a/tests/auto/network/access/qnetworkreply/BLACKLIST b/tests/auto/network/access/qnetworkreply/BLACKLIST index 1d56c78bbc..d6fc717e37 100644 --- a/tests/auto/network/access/qnetworkreply/BLACKLIST +++ b/tests/auto/network/access/qnetworkreply/BLACKLIST @@ -1,5 +1,7 @@ # See qtbase/src/testlib/qtestblacklist.cpp for format osx +[authenticationCacheAfterCancel] +windows [ioGetFromBuiltinHttp:http+limited] ubuntu-14.04 [ioGetFromBuiltinHttp:https+limited] @@ -8,3 +10,33 @@ ubuntu-14.04 * [backgroundRequestInterruption:ftp, bg, nobg] * +[getErrors:ftp-host] +linux +[getFromHttpIntoBuffer] +windows +[getFromHttpIntoBuffer2] +windows +[headFromHttp] +windows +[ioGetFromHttpWithSocksProxy] +windows +[ioPostToHttpFromSocket] +windows +[ioHttpRedirectMultipartPost] +linux +[ioHttpRedirectPolicy] +b2qt 64bit +linux +[ioHttpRedirectPostPut] +linux +windows +[putToFtp] +windows ci +[putWithServerClosingConnectionImmediately] +windows +[qtbug28035browserDoesNotLoadQtProjectOrgCorrectly] +windows +[getFromUnreachableIp] +windows msvc-2017 +[ioHttpRedirectErrors:too-many-redirects] +rhel-6.6 ci diff --git a/tests/auto/network/access/qnetworkreply/test/test.pro b/tests/auto/network/access/qnetworkreply/test/test.pro index 0dcf5a250c..1f45ac0c49 100644 --- a/tests/auto/network/access/qnetworkreply/test/test.pro +++ b/tests/auto/network/access/qnetworkreply/test/test.pro @@ -13,7 +13,4 @@ RESOURCES += ../qnetworkreply.qrc TESTDATA += ../empty ../rfc3252.txt ../resource ../bigfile ../*.jpg ../certs \ ../index.html ../smb-file.txt -qtConfig(xcb): CONFIG+=insignificant_test # unstable, QTBUG-21102 -win32:CONFIG += insignificant_test # QTBUG-24226 - !winrt: TEST_HELPER_INSTALLS = ../echo/echo diff --git a/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp b/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp index f6e3962454..df68d4fcd5 100644 --- a/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp +++ b/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp @@ -33,6 +33,7 @@ #include <QtCore/QUrl> #include <QtCore/QEventLoop> #include <QtCore/QFile> +#include <QtCore/QRandomGenerator> #include <QtCore/QSharedPointer> #include <QtCore/QScopedPointer> #include <QtCore/QTemporaryFile> @@ -120,12 +121,11 @@ class tst_QNetworkReply: public QObject static QString createUniqueExtension() { if (!seedCreated) { - qsrand(QTime(0,0,0).msecsTo(QTime::currentTime()) + QCoreApplication::applicationPid()); seedCreated = true; // not thread-safe, but who cares } return QString::number(QTime(0, 0, 0).msecsTo(QTime::currentTime())) + QLatin1Char('-') + QString::number(QCoreApplication::applicationPid()) - + QLatin1Char('-') + QString::number(qrand()); + + QLatin1Char('-') + QString::number(QRandomGenerator::global()->generate()); } static QString tempRedirectReplyStr() { @@ -491,10 +491,12 @@ private Q_SLOTS: void ioHttpRedirect_data(); void ioHttpRedirect(); void ioHttpRedirectFromLocalToRemote(); - void ioHttpRedirectPost_data(); - void ioHttpRedirectPost(); + void ioHttpRedirectPostPut_data(); + void ioHttpRedirectPostPut(); void ioHttpRedirectMultipartPost_data(); void ioHttpRedirectMultipartPost(); + void ioHttpRedirectDelete(); + void ioHttpRedirectCustom(); #ifndef QT_NO_SSL void putWithServerClosingConnectionImmediately(); #endif @@ -2002,6 +2004,16 @@ void tst_QNetworkReply::getErrors_data() << int(QNetworkReply::AuthenticationRequiredError) << 401 << false; } +static QByteArray msgGetErrors(int waitResult, const QNetworkReplyPtr &reply) +{ + QByteArray result ="waitResult=" + QByteArray::number(waitResult); + if (reply->isFinished()) + result += ", finished"; + if (reply->error() != QNetworkReply::NoError) + result += ", error: " + QByteArray::number(int(reply->error())); + return result; +} + void tst_QNetworkReply::getErrors() { QFETCH(QString, url); @@ -2031,7 +2043,8 @@ void tst_QNetworkReply::getErrors() QCOMPARE(reply->error(), QNetworkReply::NoError); // now run the request: - QVERIFY(waitForFinish(reply) != Timeout); + const int waitResult = waitForFinish(reply); + QVERIFY2(waitResult != Timeout, msgGetErrors(waitResult, reply)); QFETCH(int, error); QEXPECT_FAIL("ftp-is-dir", "QFtp cannot provide enough detail", Abort); @@ -4860,7 +4873,7 @@ void tst_QNetworkReply::ioPostToHttpsUploadProgress() // server send the data much faster than expected. // So better provide random data that cannot be compressed. for (int i = 0; i < wantedSize; ++i) - sourceFile += (char)qrand(); + sourceFile += (char)QRandomGenerator::global()->generate(); // emulate a minimal https server SslServer server; @@ -4940,7 +4953,7 @@ void tst_QNetworkReply::ioGetFromBuiltinHttp() // server send the data much faster than expected. // So better provide random data that cannot be compressed. for (int i = 0; i < wantedSize; ++i) - testData += (char)qrand(); + testData += (char)QRandomGenerator::global()->generate(); QByteArray httpResponse = QByteArray("HTTP/1.0 200 OK\r\nContent-Length: "); httpResponse += QByteArray::number(testData.size()); @@ -6763,6 +6776,48 @@ void tst_QNetworkReply::getFromUnreachableIp() { QNetworkAccessManager manager; +#ifdef Q_OS_WIN + // This test assumes that attempt to connect to 255.255.255.255 fails more + // or less fast/immediately. This is not what we observe on Windows: + // WSAConnect on non-blocking socket returns SOCKET_ERROR, WSAGetLastError + // returns WSAEWOULDBLOCK (expected) and getsockopt most of the time returns + // NOERROR; so socket engine starts a timer (30 s.) and waits for a timeout/ + // error/success. Unfortunately, the test itself is waiting only for 5 s. + // So we have to adjust the connection timeout or skip the test completely + // if the 'bearermanagement' feature is not available. +#if QT_CONFIG(bearermanagement) + class ConfigurationGuard + { + public: + explicit ConfigurationGuard(QNetworkAccessManager *m) + : manager(m) + { + Q_ASSERT(m); + auto conf = manager->configuration(); + previousTimeout = conf.connectTimeout(); + conf.setConnectTimeout(1500); + manager->setConfiguration(conf); + } + ~ConfigurationGuard() + { + Q_ASSERT(manager); + auto conf = manager->configuration(); + conf.setConnectTimeout(previousTimeout); + manager->setConfiguration(conf); + } + private: + QNetworkAccessManager *manager = nullptr; + int previousTimeout = 0; + + Q_DISABLE_COPY(ConfigurationGuard) + }; + + const ConfigurationGuard restorer(&manager); +#else // bearermanagement + QSKIP("This test is non-deterministic on Windows x86"); +#endif // !bearermanagement +#endif // Q_OS_WIN + QNetworkRequest request(QUrl("http://255.255.255.255/42/23/narf/narf/narf")); QNetworkReplyPtr reply(manager.get(request)); @@ -8563,37 +8618,46 @@ void tst_QNetworkReply::ioHttpRedirectFromLocalToRemote() QCOMPARE(reply->readAll(), reference.readAll()); } -void tst_QNetworkReply::ioHttpRedirectPost_data() +void tst_QNetworkReply::ioHttpRedirectPostPut_data() { + QTest::addColumn<bool>("usePost"); QTest::addColumn<QString>("status"); QTest::addColumn<QByteArray>("data"); QTest::addColumn<QString>("contentType"); QByteArray data; data = "hello world"; - QTest::addRow("307") << "307 Temporary Redirect" << data << "text/plain"; + QTest::addRow("post-307") << true << "307 Temporary Redirect" << data << "text/plain"; + QTest::addRow("put-307") << false << "307 Temporary Redirect" << data << "text/plain"; QString permanentRedirect = "308 Permanent Redirect"; - QTest::addRow("308") << permanentRedirect << data << "text/plain"; + QTest::addRow("post-308") << true << permanentRedirect << data << "text/plain"; + QTest::addRow("put-308") << false << permanentRedirect << data << "text/plain"; // Some data from ::putToFile_data data = ""; - QTest::newRow("empty") << permanentRedirect << data << "application/octet-stream"; + QTest::newRow("post-empty") << true << permanentRedirect << data << "application/octet-stream"; + QTest::newRow("put-empty") << false << permanentRedirect << data << "application/octet-stream"; data = QByteArray("abcd\0\1\2\abcd",12); - QTest::newRow("with-nul") << permanentRedirect << data << "application/octet-stream"; + QTest::newRow("post-with-nul") << true << permanentRedirect << data << "application/octet-stream"; + QTest::newRow("put-with-nul") << false << permanentRedirect << data << "application/octet-stream"; data = QByteArray(4097, '\4'); - QTest::newRow("4k+1") << permanentRedirect << data << "application/octet-stream"; + QTest::newRow("post-4k+1") << true << permanentRedirect << data << "application/octet-stream"; + QTest::newRow("put-4k+1") << false << permanentRedirect << data << "application/octet-stream"; data = QByteArray(128*1024+1, '\177'); - QTest::newRow("128k+1") << permanentRedirect << data << "application/octet-stream"; + QTest::newRow("post-128k+1") << true << permanentRedirect << data << "application/octet-stream"; + QTest::newRow("put-128k+1") << false << permanentRedirect << data << "application/octet-stream"; data = QByteArray(2*1024*1024+1, '\177'); - QTest::newRow("2MB+1") << permanentRedirect << data << "application/octet-stream"; + QTest::newRow("post-2MB+1") << true << permanentRedirect << data << "application/octet-stream"; + QTest::newRow("put-2MB+1") << false << permanentRedirect << data << "application/octet-stream"; } -void tst_QNetworkReply::ioHttpRedirectPost() +void tst_QNetworkReply::ioHttpRedirectPostPut() { + QFETCH(bool, usePost); QFETCH(QString, status); QFETCH(QByteArray, data); QFETCH(QString, contentType); @@ -8612,7 +8676,7 @@ void tst_QNetworkReply::ioHttpRedirectPost() auto oldRedirectPolicy = manager.redirectPolicy(); manager.setRedirectPolicy(QNetworkRequest::RedirectPolicy::NoLessSafeRedirectPolicy); - QNetworkReplyPtr reply(manager.post(request, data)); + QNetworkReplyPtr reply(usePost ? manager.post(request, data) : manager.put(request, data)); // Restore previous policy: manager.setRedirectPolicy(oldRedirectPolicy); @@ -8681,6 +8745,50 @@ void tst_QNetworkReply::ioHttpRedirectMultipartPost() QCOMPARE(replyData, expectedReplyData); } +void tst_QNetworkReply::ioHttpRedirectDelete() +{ + MiniHttpServer target(httpEmpty200Response, false); + QUrl targetUrl("http://localhost/"); + targetUrl.setPort(target.serverPort()); + + QString redirectReply = tempRedirectReplyStr().arg(targetUrl.toString()); + MiniHttpServer redirectServer(redirectReply.toLatin1()); + QUrl url("http://localhost/"); + url.setPort(redirectServer.serverPort()); + QNetworkRequest request(url); + auto oldRedirectPolicy = manager.redirectPolicy(); + manager.setRedirectPolicy(QNetworkRequest::RedirectPolicy::NoLessSafeRedirectPolicy); + + QNetworkReplyPtr reply(manager.deleteResource(request)); + // Restore previous policy: + manager.setRedirectPolicy(oldRedirectPolicy); + + QCOMPARE(waitForFinish(reply), int(Success)); + QVERIFY2(target.receivedData.startsWith("DELETE"), "Target server called with the wrong method"); +} + +void tst_QNetworkReply::ioHttpRedirectCustom() +{ + MiniHttpServer target(httpEmpty200Response, false); + QUrl targetUrl("http://localhost/"); + targetUrl.setPort(target.serverPort()); + + QString redirectReply = tempRedirectReplyStr().arg(targetUrl.toString()); + MiniHttpServer redirectServer(redirectReply.toLatin1()); + QUrl url("http://localhost/"); + url.setPort(redirectServer.serverPort()); + QNetworkRequest request(url); + auto oldRedirectPolicy = manager.redirectPolicy(); + manager.setRedirectPolicy(QNetworkRequest::RedirectPolicy::NoLessSafeRedirectPolicy); + + QNetworkReplyPtr reply(manager.sendCustomRequest(request, QByteArrayLiteral("CUSTOM"))); + // Restore previous policy: + manager.setRedirectPolicy(oldRedirectPolicy); + + QCOMPARE(waitForFinish(reply), int(Success)); + QVERIFY2(target.receivedData.startsWith("CUSTOM"), "Target server called with the wrong method"); +} + #ifndef QT_NO_SSL class PutWithServerClosingConnectionImmediatelyHandler: public QObject @@ -8710,7 +8818,7 @@ public slots: m_receivedData += data; if (!m_parsedHeaders && m_receivedData.contains("\r\n\r\n")) { m_parsedHeaders = true; - QTimer::singleShot(qrand()%60, this, SLOT(closeDelayed())); // simulate random network latency + QTimer::singleShot(QRandomGenerator::global()->bounded(60), this, SLOT(closeDelayed())); // simulate random network latency // This server simulates a web server connection closing, e.g. because of Apaches MaxKeepAliveRequests or KeepAliveTimeout // In this case QNAM needs to re-send the upload data but it had a bug which then corrupts the upload // This test catches that. |