summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@qt.io>2019-07-26 10:13:06 +0200
committerLiang Qi <liang.qi@qt.io>2019-07-26 10:13:06 +0200
commitbf08e0bbb28917f1965cd29ed449e553d1d1f4f1 (patch)
treeed83933e4f6a9d40c546c85aa136f18ce927dfc8 /tests
parent547f216efdef3667b0b23ecddce93e5184806800 (diff)
parent0ce3f7d62b93427ca5d0f4284ba774691cbbd4a7 (diff)
Merge remote-tracking branch 'origin/5.12' into 5.13
Conflicts: src/network/access/qhttpthreaddelegate.cpp Change-Id: Id47b977587e2d713c16ac17e63c5ec80c2f05ee9
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/network/access/http2/tst_http2.cpp123
-rw-r--r--tests/benchmarks/gui/painting/lancebench/tst_lancebench.cpp20
2 files changed, 133 insertions, 10 deletions
diff --git a/tests/auto/network/access/http2/tst_http2.cpp b/tests/auto/network/access/http2/tst_http2.cpp
index 502ffba3de..bf3d936446 100644
--- a/tests/auto/network/access/http2/tst_http2.cpp
+++ b/tests/auto/network/access/http2/tst_http2.cpp
@@ -85,6 +85,8 @@ private slots:
void goaway_data();
void goaway();
void earlyResponse();
+ void connectToHost_data();
+ void connectToHost();
protected slots:
// Slots to listen to our in-process server:
@@ -545,6 +547,127 @@ void tst_Http2::earlyResponse()
QVERIFY(serverGotSettingsACK);
}
+void tst_Http2::connectToHost_data()
+{
+ // The attribute to set on a new request:
+ QTest::addColumn<QNetworkRequest::Attribute>("requestAttribute");
+ // The corresponding (to the attribute above) connection type the
+ // server will use:
+ QTest::addColumn<H2Type>("connectionType");
+
+#if QT_CONFIG(ssl)
+ QTest::addRow("encrypted-h2-direct") << QNetworkRequest::Http2DirectAttribute << H2Type::h2Direct;
+ if (!clearTextHTTP2)
+ QTest::addRow("encrypted-h2-ALPN") << QNetworkRequest::HTTP2AllowedAttribute << H2Type::h2Alpn;
+#endif // QT_CONFIG(ssl)
+ // This works for all configurations, tests 'preconnect-http' scheme:
+ // h2 with protocol upgrade is not working for now (the logic is a bit
+ // complicated there ...).
+ QTest::addRow("h2-direct") << QNetworkRequest::Http2DirectAttribute << H2Type::h2cDirect;
+}
+
+void tst_Http2::connectToHost()
+{
+ // QNetworkAccessManager::connectToHostEncrypted() and connectToHost()
+ // creates a special request with 'preconnect-https' or 'preconnect-http'
+ // schemes. At the level of the protocol handler we are supposed to report
+ // these requests as finished and wait for the real requests. This test will
+ // connect to a server with the first reply 'finished' signal meaning we
+ // indeed connected. At this point we check that a client preface was not
+ // sent yet, and no response received. Then we send the second (the real)
+ // request and do our usual checks. Since our server closes its listening
+ // socket on the first incoming connection (would not accept a new one),
+ // the successful completion of the second requests also means we were able
+ // to find a cached connection and re-use it.
+
+ QFETCH(const QNetworkRequest::Attribute, requestAttribute);
+ QFETCH(const H2Type, connectionType);
+
+ clearHTTP2State();
+
+ serverPort = 0;
+ nRequests = 2;
+
+ ServerPtr targetServer(newServer(defaultServerSettings, connectionType));
+
+#if QT_CONFIG(ssl)
+ Q_ASSERT(!clearTextHTTP2 || connectionType != H2Type::h2Alpn);
+#else
+ Q_ASSERT(connectionType == H2Type::h2c || connectionType == H2Type::h2cDirect);
+ Q_ASSERT(targetServer->isClearText());
+#endif // QT_CONFIG(ssl)
+
+ QMetaObject::invokeMethod(targetServer.data(), "startServer", Qt::QueuedConnection);
+ runEventLoop();
+
+ QVERIFY(serverPort != 0);
+
+ auto url = requestUrl(connectionType);
+ url.setPath("/index.html");
+
+ QNetworkReply *reply = nullptr;
+ // Here some mess with how we create this first reply:
+#if QT_CONFIG(ssl)
+ if (!targetServer->isClearText()) {
+ // Let's emulate what QNetworkAccessManager::connectToHostEncrypted() does.
+ // Alas, we cannot use it directly, since it does not return the reply and
+ // also does not know the difference between H2 with ALPN or direct.
+ auto copyUrl = url;
+ copyUrl.setScheme(QLatin1String("preconnect-https"));
+ QNetworkRequest request(copyUrl);
+ request.setAttribute(requestAttribute, true);
+ reply = manager->get(request);
+ // Since we're using self-signed certificates, ignore SSL errors:
+ reply->ignoreSslErrors();
+ } else
+#endif // QT_CONFIG(ssl)
+ {
+ // Emulating what QNetworkAccessManager::connectToHost() does with
+ // additional information that it cannot provide (the attribute).
+ auto copyUrl = url;
+ copyUrl.setScheme(QLatin1String("preconnect-http"));
+ QNetworkRequest request(copyUrl);
+ request.setAttribute(requestAttribute, true);
+ reply = manager->get(request);
+ }
+
+ connect(reply, &QNetworkReply::finished, [this, reply]() {
+ --nRequests;
+ eventLoop.exitLoop();
+ QCOMPARE(reply->error(), QNetworkReply::NoError);
+ QVERIFY(reply->isFinished());
+ // Nothing must be sent yet:
+ QVERIFY(!prefaceOK);
+ QVERIFY(!serverGotSettingsACK);
+ // Nothing received back:
+ QVERIFY(reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).isNull());
+ QCOMPARE(reply->readAll().size(), 0);
+ });
+
+ runEventLoop();
+ STOP_ON_FAILURE
+
+ QCOMPARE(nRequests, 1);
+
+ QNetworkRequest request(url);
+ request.setAttribute(requestAttribute, QVariant(true));
+ reply = manager->get(request);
+ connect(reply, &QNetworkReply::finished, this, &tst_Http2::replyFinished);
+ // Note, unlike the first request, when the connection is ecnrytped, we
+ // do not ignore TLS errors on this reply - we should re-use existing
+ // connection, there TLS errors were already ignored.
+
+ runEventLoop();
+ STOP_ON_FAILURE
+
+ QVERIFY(nRequests == 0);
+ QVERIFY(prefaceOK);
+ QVERIFY(serverGotSettingsACK);
+
+ QCOMPARE(reply->error(), QNetworkReply::NoError);
+ QVERIFY(reply->isFinished());
+}
+
void tst_Http2::serverStarted(quint16 port)
{
serverPort = port;
diff --git a/tests/benchmarks/gui/painting/lancebench/tst_lancebench.cpp b/tests/benchmarks/gui/painting/lancebench/tst_lancebench.cpp
index bd0889bf4a..d26ac016b9 100644
--- a/tests/benchmarks/gui/painting/lancebench/tst_lancebench.cpp
+++ b/tests/benchmarks/gui/painting/lancebench/tst_lancebench.cpp
@@ -305,17 +305,17 @@ void tst_LanceBench::runTestSuite(GraphicsEngine engine, QImage::Format format,
void tst_LanceBench::paint(QPaintDevice *device, GraphicsEngine engine, QImage::Format format, const QStringList &script, const QString &filePath)
{
- PaintCommands pcmd(script, 800, 800, format);
- switch (engine) {
- case OpenGL:
- pcmd.setType(OpenGLBufferType); // version/profile is communicated through the context's format()
- break;
- case Raster:
- pcmd.setType(ImageType);
- break;
- }
- pcmd.setFilePath(filePath);
QBENCHMARK {
+ PaintCommands pcmd(script, 800, 800, format);
+ switch (engine) {
+ case OpenGL:
+ pcmd.setType(OpenGLBufferType); // version/profile is communicated through the context's format()
+ break;
+ case Raster:
+ pcmd.setType(ImageType);
+ break;
+ }
+ pcmd.setFilePath(filePath);
QPainter p(device);
pcmd.setPainter(&p);
pcmd.runCommands();