diff --git a/src/webengine/api/qquickwebenginedownloaditem.cpp b/src/webengine/api/qquickwebenginedownloaditem.cpp index f9b305e887f4537a15147641f819ad9636d6bae3..3ccd27094cfbefde4b23885cc00514f985a05d29 100644 --- a/src/webengine/api/qquickwebenginedownloaditem.cpp +++ b/src/webengine/api/qquickwebenginedownloaditem.cpp @@ -463,7 +463,7 @@ void QQuickWebEngineDownloadItem::setPath(QString path) newDirectory = QStringLiteral(""); newFileName = path; } else { - newDirectory = QFileInfo(path).filePath(); + newDirectory = QFileInfo(path).path(); newFileName = QFileInfo(path).fileName(); } diff --git a/src/webenginewidgets/api/qwebenginedownloaditem.cpp b/src/webenginewidgets/api/qwebenginedownloaditem.cpp index 7b0cfe074620694838dc390ef1defc364fa5bfbe..e1bfc506f27ced3cca1fd6945e0946c3e32293d7 100644 --- a/src/webenginewidgets/api/qwebenginedownloaditem.cpp +++ b/src/webenginewidgets/api/qwebenginedownloaditem.cpp @@ -560,7 +560,7 @@ void QWebEngineDownloadItem::setPath(QString path) d->downloadDirectory = QStringLiteral(""); d->downloadFileName = path; } else { - d->downloadDirectory = QFileInfo(path).filePath(); + d->downloadDirectory = QFileInfo(path).path(); d->downloadFileName = QFileInfo(path).fileName(); } } diff --git a/tests/auto/quick/qmltests/data/tst_download.qml b/tests/auto/quick/qmltests/data/tst_download.qml index c38018ffd98749161f687579358f59e928b5d3e3..e049f36217f9dea9dbf64ea0b4e61ffcbe946d9d 100644 --- a/tests/auto/quick/qmltests/data/tst_download.qml +++ b/tests/auto/quick/qmltests/data/tst_download.qml @@ -47,6 +47,7 @@ TestWebEngineView { property string downloadDirectory: "" property string downloadFileName: "" property string downloadedPath: "" + property string downloadedSetPath: "" property int downloadDirectoryChanged: 0 property int downloadFileNameChanged: 0 property int downloadPathChanged: 0 @@ -94,14 +95,19 @@ TestWebEngineView { } else { totalBytes = download.totalBytes - download.downloadDirectory = downloadDirectory.length != 0 ? testDownloadProfile.downloadPath + downloadDirectory : testDownloadProfile.downloadPath - download.downloadFileName = downloadFileName.length != 0 ? downloadFileName : "testfile.zip" + if (downloadedSetPath.length != 0) { + download.path = testDownloadProfile.downloadPath + downloadedSetPath + downloadedPath = download.path + } else { + download.downloadDirectory = downloadDirectory.length != 0 ? testDownloadProfile.downloadPath + downloadDirectory : testDownloadProfile.downloadPath + download.downloadFileName = downloadFileName.length != 0 ? downloadFileName : "testfile.zip" + downloadedPath = download.downloadDirectory + download.downloadFileName + } download.accept() } downloadUrl = download.url suggestedFileName = download.suggestedFileName - downloadedPath = download.downloadDirectory + download.downloadFileName } onDownloadFinished: { receivedBytes = download.receivedBytes; @@ -126,6 +132,7 @@ TestWebEngineView { downloadDirectory = "" downloadFileName = "" downloadedPath = "" + downloadedSetPath = "" } function test_downloadRequest() { @@ -211,5 +218,27 @@ TestWebEngineView { tryCompare(downloadState, "2", WebEngineDownloadItem.DownloadCompleted); verify(!downloadInterruptReason); } + + function test_downloadWithSetPath() { + compare(downLoadRequestedSpy.count, 0); + compare(downloadDirectoryChanged, 0); + compare(downloadFileNameChanged, 0); + downloadedSetPath = "/test/test.zip"; + webEngineView.url = Qt.resolvedUrl("download.zip"); + downLoadRequestedSpy.wait(); + compare(downLoadRequestedSpy.count, 1); + compare(downloadUrl, webEngineView.url); + compare(suggestedFileName, "download.zip"); + compare(downloadState[0], WebEngineDownloadItem.DownloadRequested); + tryCompare(downloadState, "1", WebEngineDownloadItem.DownloadInProgress); + compare(downloadedPath, testDownloadProfile.downloadPath + downloadedSetPath); + compare(downloadDirectoryChanged, 1); + compare(downloadFileNameChanged, 1); + compare(downloadPathChanged, 2); + downloadFinishedSpy.wait(); + compare(totalBytes, receivedBytes); + tryCompare(downloadState, "2", WebEngineDownloadItem.DownloadCompleted); + verify(!downloadInterruptReason); + } } }