diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2019-01-22 22:32:33 +0000 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2019-01-22 22:32:33 +0000 |
commit | e11adebe6f4f76a3e3253b33314a2b4635dc3e65 (patch) | |
tree | e2a5a7c08b0956b9b1731c7d3c0ec97db363b762 /tests/auto/widgets | |
parent | 10d849f82e0408350d9235cafdf04cc654ac0046 (diff) | |
parent | 8b2427f2c8de0a7c8f06318e8fe7849182621f68 (diff) |
Merge "Merge remote-tracking branch 'origin/5.12' into dev" into refs/staging/dev
Diffstat (limited to 'tests/auto/widgets')
-rw-r--r-- | tests/auto/widgets/qwebenginedownloaditem/tst_qwebenginedownloaditem.cpp | 44 |
1 files changed, 39 insertions, 5 deletions
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" |