From a7454f915d3db7d6711f6ad5e9991606aec3c4a5 Mon Sep 17 00:00:00 2001 From: Peter Varga Date: Fri, 24 Feb 2023 14:57:52 +0100 Subject: Fix initialization of QWebEngineDownloadItem::totalBytes for Widgets QQuickWebEngineProfile already initializes totalBytes. Also fix typo in documentation. Fixes: QTBUG-104869 Change-Id: I8c4b79c076ddc63180960e22a9488b45ff6c4402 Reviewed-by: Allan Sandfeld Jensen (cherry picked from commit 496647f7647571ca3cdf81b10ba418de0f06f34d) Reviewed-by: Michal Klocek --- src/core/download_manager_delegate_qt.cpp | 2 +- src/webenginewidgets/api/qwebenginedownloaditem.cpp | 2 +- src/webenginewidgets/api/qwebengineprofile.cpp | 1 + .../widgets/qwebenginedownloaditem/tst_qwebenginedownloaditem.cpp | 4 ++-- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/core/download_manager_delegate_qt.cpp b/src/core/download_manager_delegate_qt.cpp index f1ad1e677..b694d1759 100644 --- a/src/core/download_manager_delegate_qt.cpp +++ b/src/core/download_manager_delegate_qt.cpp @@ -295,7 +295,7 @@ void DownloadManagerDelegateQt::ChooseSavePath(content::WebContents *web_content ++m_currentId, toQt(web_contents->GetURL()), download::DownloadItem::IN_PROGRESS, - 0, /* totalBytes */ + -1, /* totalBytes */ 0, /* receivedBytes */ QStringLiteral("application/x-mimearchive"), suggestedFilePath, diff --git a/src/webenginewidgets/api/qwebenginedownloaditem.cpp b/src/webenginewidgets/api/qwebenginedownloaditem.cpp index 7366dbf59..d44b9e4e9 100644 --- a/src/webenginewidgets/api/qwebenginedownloaditem.cpp +++ b/src/webenginewidgets/api/qwebenginedownloaditem.cpp @@ -465,7 +465,7 @@ QWebEngineDownloadItem::DownloadState QWebEngineDownloadItem::state() const } /*! - Returns the the total amount of data to download in bytes. + Returns the total amount of data to download in bytes. \c -1 means the size is unknown. */ diff --git a/src/webenginewidgets/api/qwebengineprofile.cpp b/src/webenginewidgets/api/qwebengineprofile.cpp index 223d3b114..b25055d79 100644 --- a/src/webenginewidgets/api/qwebengineprofile.cpp +++ b/src/webenginewidgets/api/qwebengineprofile.cpp @@ -228,6 +228,7 @@ void QWebEngineProfilePrivate::downloadRequested(DownloadItemInfo &info) itemPrivate->downloadState = info.accepted ? QWebEngineDownloadItem::DownloadInProgress : QWebEngineDownloadItem::DownloadRequested; itemPrivate->startTime = info.startTime; + itemPrivate->totalBytes = info.totalBytes; itemPrivate->downloadDirectory = QFileInfo(info.path).path(); itemPrivate->downloadFileName = QFileInfo(info.path).fileName(); itemPrivate->suggestedFileName = info.suggestedFileName; diff --git a/tests/auto/widgets/qwebenginedownloaditem/tst_qwebenginedownloaditem.cpp b/tests/auto/widgets/qwebenginedownloaditem/tst_qwebenginedownloaditem.cpp index 9a3e7b52e..74082ab8c 100644 --- a/tests/auto/widgets/qwebenginedownloaditem/tst_qwebenginedownloaditem.cpp +++ b/tests/auto/widgets/qwebenginedownloaditem/tst_qwebenginedownloaditem.cpp @@ -455,7 +455,7 @@ void tst_QWebEngineDownloadItem::downloadLink() ScopedConnection sc2 = connect(m_profile, &QWebEngineProfile::downloadRequested, [&](QWebEngineDownloadItem *item) { QCOMPARE(item->state(), QWebEngineDownloadItem::DownloadRequested); QCOMPARE(item->isFinished(), false); - QCOMPARE(item->totalBytes(), -1); + QCOMPARE(item->totalBytes(), fileContents.size()); QCOMPARE(item->receivedBytes(), 0); QCOMPARE(item->interruptReason(), QWebEngineDownloadItem::NoReason); QCOMPARE(item->type(), expectedDownloadType(userAction, fileDisposition)); @@ -568,7 +568,7 @@ void tst_QWebEngineDownloadItem::downloadTwoLinks() ScopedConnection sc2 = connect(m_profile, &QWebEngineProfile::downloadRequested, [&](QWebEngineDownloadItem *item) { QCOMPARE(item->state(), QWebEngineDownloadItem::DownloadRequested); QCOMPARE(item->isFinished(), false); - QCOMPARE(item->totalBytes(), -1); + QCOMPARE(item->totalBytes(), 5); // strlen("fileN") QCOMPARE(item->receivedBytes(), 0); QCOMPARE(item->interruptReason(), QWebEngineDownloadItem::NoReason); QCOMPARE(item->savePageFormat(), QWebEngineDownloadItem::UnknownSaveFormat); -- cgit v1.2.1