summaryrefslogtreecommitdiffstats
path: root/tests/auto/widgets/qwebengineprofile
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@theqtcompany.com>2016-05-12 14:35:34 +0200
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2016-05-13 12:00:22 +0000
commitd1d64e6e66f53ccd4eb0a548e9ce726190ebae91 (patch)
tree19c25199910927ccb6535bf1be60b67e4d0ce02d /tests/auto/widgets/qwebengineprofile
parent0f721b93f908828952b17f2f71a66c938f680fb1 (diff)
Better handle failure on read in custom url handlers
Chromium 49 expects url request failures to be reported as a response to either start or on read. So we should report failures during read and make sure we can handle QIODevice calling fail on the job. Change-Id: Id8f619d3cb6f187c99da580c6923130a95ca91ee Reviewed-by: Michael BrĂ¼ning <michael.bruning@theqtcompany.com>
Diffstat (limited to 'tests/auto/widgets/qwebengineprofile')
-rw-r--r--tests/auto/widgets/qwebengineprofile/tst_qwebengineprofile.cpp54
1 files changed, 53 insertions, 1 deletions
diff --git a/tests/auto/widgets/qwebengineprofile/tst_qwebengineprofile.cpp b/tests/auto/widgets/qwebengineprofile/tst_qwebengineprofile.cpp
index 95d5cf16..a399f556 100644
--- a/tests/auto/widgets/qwebengineprofile/tst_qwebengineprofile.cpp
+++ b/tests/auto/widgets/qwebengineprofile/tst_qwebengineprofile.cpp
@@ -47,6 +47,7 @@ private Q_SLOTS:
void disableCache();
void urlSchemeHandlers();
void urlSchemeHandlerFailRequest();
+ void urlSchemeHandlerFailOnRead();
void customUserAgent();
void httpAcceptLanguage();
};
@@ -237,10 +238,47 @@ class FailingUrlSchemeHandler : public QWebEngineUrlSchemeHandler
public:
void requestStarted(QWebEngineUrlRequestJob *job) override
{
- job->fail(QWebEngineUrlRequestJob::RequestFailed);
+ job->fail(QWebEngineUrlRequestJob::UrlInvalid);
}
};
+class FailingIODevice : public QIODevice
+{
+public:
+ FailingIODevice(QWebEngineUrlRequestJob *job) : m_job(job)
+ {
+ }
+
+ qint64 readData(char *, qint64) Q_DECL_OVERRIDE
+ {
+ m_job->fail(QWebEngineUrlRequestJob::RequestFailed);
+ return -1;
+ }
+ qint64 writeData(const char *, qint64) Q_DECL_OVERRIDE
+ {
+ m_job->fail(QWebEngineUrlRequestJob::RequestFailed);
+ return -1;
+ }
+ void close() Q_DECL_OVERRIDE
+ {
+ QIODevice::close();
+ deleteLater();
+ }
+
+private:
+ QWebEngineUrlRequestJob *m_job;
+};
+
+class FailOnReadUrlSchemeHandler : public QWebEngineUrlSchemeHandler
+{
+public:
+ void requestStarted(QWebEngineUrlRequestJob *job) override
+ {
+ job->reply(QByteArrayLiteral("text/plain"), new FailingIODevice(job));
+ }
+};
+
+
void tst_QWebEngineProfile::urlSchemeHandlerFailRequest()
{
FailingUrlSchemeHandler handler;
@@ -255,6 +293,20 @@ void tst_QWebEngineProfile::urlSchemeHandlerFailRequest()
QCOMPARE(toPlainTextSync(view.page()), QString());
}
+void tst_QWebEngineProfile::urlSchemeHandlerFailOnRead()
+{
+ FailOnReadUrlSchemeHandler handler;
+ QWebEngineProfile profile;
+ profile.installUrlSchemeHandler("foo", &handler);
+ QWebEngineView view;
+ QSignalSpy loadFinishedSpy(&view, SIGNAL(loadFinished(bool)));
+ view.setPage(new QWebEnginePage(&profile, &view));
+ view.settings()->setAttribute(QWebEngineSettings::ErrorPageEnabled, false);
+ view.load(QUrl(QStringLiteral("foo://bar")));
+ QVERIFY(loadFinishedSpy.wait());
+ QCOMPARE(toPlainTextSync(view.page()), QString());
+}
+
void tst_QWebEngineProfile::customUserAgent()
{
QString defaultUserAgent = QWebEngineProfile::defaultProfile()->httpUserAgent();