diff options
author | Qt Forward Merge Bot <qt_forward_merge_bot@qt-project.org> | 2019-01-22 09:30:49 +0100 |
---|---|---|
committer | Qt Forward Merge Bot <qt_forward_merge_bot@qt-project.org> | 2019-01-22 09:30:49 +0100 |
commit | 8b2427f2c8de0a7c8f06318e8fe7849182621f68 (patch) | |
tree | 673a776c93a7e16d40d7bd572f4681d3b87718c5 /tests | |
parent | c5bcd124fecaad2b7f50c59bd3790fcc4af38a20 (diff) | |
parent | 0deb1ffda77f0410b3d13419856c757cdd422d2b (diff) |
Merge remote-tracking branch 'origin/5.12' into dev
Change-Id: Ib374079ded76e43d4b72f725bbf16fe353ef827e
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/shared/httpserver.cpp | 8 | ||||
-rw-r--r-- | tests/auto/shared/httpserver.h | 3 | ||||
-rw-r--r-- | tests/auto/widgets/qwebenginedownloaditem/tst_qwebenginedownloaditem.cpp | 44 |
3 files changed, 49 insertions, 6 deletions
diff --git a/tests/auto/shared/httpserver.cpp b/tests/auto/shared/httpserver.cpp index 8d14c18ff..b85af9901 100644 --- a/tests/auto/shared/httpserver.cpp +++ b/tests/auto/shared/httpserver.cpp @@ -39,6 +39,7 @@ HttpServer::HttpServer(QObject *parent) : QObject(parent) bool HttpServer::start() { m_error = false; + m_expectingError = false; if (!m_tcpServer.listen()) { qCWarning(gHttpServerLog).noquote() << m_tcpServer.errorString(); @@ -55,7 +56,12 @@ bool HttpServer::start() bool HttpServer::stop() { m_tcpServer.close(); - return !m_error; + return m_error == m_expectingError; +} + +void HttpServer::setExpectError(bool b) +{ + m_expectingError = b; } QUrl HttpServer::url(const QString &path) const diff --git a/tests/auto/shared/httpserver.h b/tests/auto/shared/httpserver.h index ddbab433c..b4649244e 100644 --- a/tests/auto/shared/httpserver.h +++ b/tests/auto/shared/httpserver.h @@ -68,6 +68,8 @@ public: // Stops listening and performs final error checks. Q_REQUIRED_RESULT bool stop(); + void setExpectError(bool b); + // Full URL for given relative path QUrl url(const QString &path = QStringLiteral("/")) const; @@ -82,6 +84,7 @@ private: QTcpServer m_tcpServer; QUrl m_url; bool m_error = false; + bool m_expectingError = false; }; #endif // !HTTPSERVER_H diff --git a/tests/auto/widgets/qwebenginedownloaditem/tst_qwebenginedownloaditem.cpp b/tests/auto/widgets/qwebenginedownloaditem/tst_qwebenginedownloaditem.cpp index 68c549540..2af818928 100644 --- a/tests/auto/widgets/qwebenginedownloaditem/tst_qwebenginedownloaditem.cpp +++ b/tests/auto/widgets/qwebenginedownloaditem/tst_qwebenginedownloaditem.cpp @@ -34,6 +34,7 @@ #include <QWebEngineDownloadItem> #include <QWebEnginePage> #include <QWebEngineProfile> +#include <QWebEngineSettings> #include <QWebEngineView> #include <httpserver.h> @@ -67,6 +68,7 @@ private Q_SLOTS: void downloadViaSetUrl(); void downloadFileNot1(); void downloadFileNot2(); + void downloadDeleted(); private: void saveLink(QPoint linkPos); @@ -81,7 +83,8 @@ private: QWebEngineProfile *m_profile; QWebEnginePage *m_page; QWebEngineView *m_view; - QSet<QWebEngineDownloadItem *> m_downloads; + QSet<QWebEngineDownloadItem *> m_requestedDownloads; + QSet<QWebEngineDownloadItem *> m_finishedDownloads; }; class ScopedConnection { @@ -100,13 +103,15 @@ void tst_QWebEngineDownloadItem::initTestCase() m_server = new HttpServer(); m_profile = new QWebEngineProfile; m_profile->setHttpCacheType(QWebEngineProfile::NoCache); + m_profile->settings()->setAttribute(QWebEngineSettings::AutoLoadIconsForPage, false); connect(m_profile, &QWebEngineProfile::downloadRequested, [this](QWebEngineDownloadItem *item) { - m_downloads.insert(item); + m_requestedDownloads.insert(item); connect(item, &QWebEngineDownloadItem::destroyed, [this, item](){ - m_downloads.remove(item); + m_requestedDownloads.remove(item); + m_finishedDownloads.remove(item); }); connect(item, &QWebEngineDownloadItem::finished, [this, item](){ - m_downloads.remove(item); + m_finishedDownloads.insert(item); }); }); m_page = new QWebEnginePage(m_profile); @@ -123,7 +128,11 @@ void tst_QWebEngineDownloadItem::init() void tst_QWebEngineDownloadItem::cleanup() { - QCOMPARE(m_downloads.count(), 0); + for (QWebEngineDownloadItem *item : m_finishedDownloads) { + item->deleteLater(); + } + QTRY_COMPARE(m_requestedDownloads.count(), 0); + QCOMPARE(m_finishedDownloads.count(), 0); QVERIFY(m_server->stop()); } @@ -778,5 +787,30 @@ void tst_QWebEngineDownloadItem::downloadFileNot2() QCOMPARE(downloadItem->state(), QWebEngineDownloadItem::DownloadCancelled); } +void tst_QWebEngineDownloadItem::downloadDeleted() +{ + QPointer<QWebEngineDownloadItem> downloadItem; + m_server->setExpectError(true); + int downloadCount = 0; + int finishedCount = 0; + ScopedConnection sc2 = connect(m_profile, &QWebEngineProfile::downloadRequested, [&](QWebEngineDownloadItem *item) { + QVERIFY(item); + QCOMPARE(item->state(), QWebEngineDownloadItem::DownloadRequested); + downloadItem = item; + connect(downloadItem, &QWebEngineDownloadItem::finished, [&]() { + finishedCount++; + }); + item->accept(); + downloadCount++; + }); + + m_page->download(m_server->url(QByteArrayLiteral("/file"))); + QTRY_COMPARE(downloadCount, 1); + QVERIFY(downloadItem); + QCOMPARE(finishedCount, 0); + downloadItem->deleteLater(); + QTRY_COMPARE(finishedCount, 1); +} + QTEST_MAIN(tst_QWebEngineDownloadItem) #include "tst_qwebenginedownloaditem.moc" |