From 7cc93a0953e5f923699c1945b17706364f0f2160 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCri=20Valdmann?= Date: Tue, 18 Feb 2020 13:21:39 +0100 Subject: Fix CustomURLLoader not supporting responses over 64k bytes Mojo data pipes are non-blocking, meaning we have to wait until there's room in a buffer before we can transfer data from the QIODevice to the pipe. Use mojo::SimpleWatcher to monitor the pipe for readiness and use the two-phase BeginWriteData/EndWriteData API to let the QIODevice write directly into the pipe's internal buffer, avoiding a copy. Fixes: QTBUG-82244 Change-Id: I65e69ce72d0e99bc047c57b5a22531c0891c553a Reviewed-by: Peter Varga --- .../qwebengineprofile/tst_qwebengineprofile.cpp | 28 +++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/auto/widgets/qwebengineprofile/tst_qwebengineprofile.cpp b/tests/auto/widgets/qwebengineprofile/tst_qwebengineprofile.cpp index eed9c071a..1dd8a38c8 100644 --- a/tests/auto/widgets/qwebengineprofile/tst_qwebengineprofile.cpp +++ b/tests/auto/widgets/qwebengineprofile/tst_qwebengineprofile.cpp @@ -67,6 +67,7 @@ private Q_SLOTS: void urlSchemeHandlerInstallation(); void urlSchemeHandlerXhrStatus(); void urlSchemeHandlerScriptModule(); + void urlSchemeHandlerLongReply(); void customUserAgent(); void httpAcceptLanguage(); void downloadItem(); @@ -294,7 +295,7 @@ protected: memcpy(data, m_data.constData() + m_bytesRead, len); m_bytesAvailable -= len; m_bytesRead += len; - } else if (m_data.size() > 0) + } else if (atEnd()) return -1; return len; @@ -714,6 +715,31 @@ void tst_QWebEngineProfile::urlSchemeHandlerScriptModule() QCOMPARE(evaluateJavaScriptSync(&page, QStringLiteral("test")).toString(), QStringLiteral("SUCCESS")); } +class LongReplyUrlSchemeHandler : public QWebEngineUrlSchemeHandler +{ +public: + LongReplyUrlSchemeHandler(QObject *parent = nullptr) : QWebEngineUrlSchemeHandler(parent) {} + ~LongReplyUrlSchemeHandler() {} + + void requestStarted(QWebEngineUrlRequestJob *job) + { + QBuffer *buffer = new QBuffer(job); + buffer->setData(QByteArray(128 * 1024, ' ') + + "Minify this!"); + job->reply("text/html", buffer); + } +}; + +void tst_QWebEngineProfile::urlSchemeHandlerLongReply() +{ + LongReplyUrlSchemeHandler handler; + QWebEngineProfile profile; + profile.installUrlSchemeHandler("aviancarrier", &handler); + QWebEnginePage page(&profile); + page.load(QUrl("aviancarrier:/")); + QTRY_COMPARE(page.title(), QString("Minify this!")); +} + void tst_QWebEngineProfile::customUserAgent() { QString defaultUserAgent = QWebEngineProfile::defaultProfile()->httpUserAgent(); -- cgit v1.2.3