From 0884fab3b161b62c1e2bb1bac6bbd74560f06232 Mon Sep 17 00:00:00 2001 From: Tamas Zakor Date: Tue, 28 May 2019 13:54:28 +0200 Subject: Add API to change download directory path and file name Add functions and property to change the download directory and file name in QWebEngineDownloadItem and QQuickWebEngineDownloadItem and deprecate the path() and setPath(). Regenerating the uniquifying download filename after change the download directory. [ChangeLog][DownloadItem] Add functions and property to change the download directory and file name in QWebEngineDownloadItem and QQuickWebEngineDownloadItem and deprecate the path() and setPath(). Task-number: QTBUG-56978 Change-Id: I6e63da82a187add8bc3206cc80c8bf6865fbdd35 Reviewed-by: Allan Sandfeld Jensen --- tests/auto/quick/publicapi/tst_publicapi.cpp | 4 +++ tests/auto/quick/qmltests/data/tst_download.qml | 47 ++++++++++++++++++++++++- 2 files changed, 50 insertions(+), 1 deletion(-) (limited to 'tests/auto/quick') diff --git a/tests/auto/quick/publicapi/tst_publicapi.cpp b/tests/auto/quick/publicapi/tst_publicapi.cpp index 8b8eb8636..f464d58d0 100644 --- a/tests/auto/quick/publicapi/tst_publicapi.cpp +++ b/tests/auto/quick/publicapi/tst_publicapi.cpp @@ -262,6 +262,10 @@ static const QStringList expectedAPI = QStringList() << "QQuickWebEngineDownloadItem.view --> QQuickWebEngineView*" << "QQuickWebEngineDownloadItem.url --> QUrl" << "QQuickWebEngineDownloadItem.suggestedFileName --> QString" + << "QQuickWebEngineDownloadItem.downloadDirectory --> QString" + << "QQuickWebEngineDownloadItem.downloadDirectoryChanged() --> void" + << "QQuickWebEngineDownloadItem.downloadFileName --> QString" + << "QQuickWebEngineDownloadItem.downloadFileNameChanged() --> void" << "QQuickWebEngineFileDialogRequest.FileModeOpen --> FileMode" << "QQuickWebEngineFileDialogRequest.FileModeOpenMultiple --> FileMode" << "QQuickWebEngineFileDialogRequest.FileModeSave --> FileMode" diff --git a/tests/auto/quick/qmltests/data/tst_download.qml b/tests/auto/quick/qmltests/data/tst_download.qml index c8f783b03..ff57c76c7 100644 --- a/tests/auto/quick/qmltests/data/tst_download.qml +++ b/tests/auto/quick/qmltests/data/tst_download.qml @@ -44,6 +44,12 @@ TestWebEngineView { property var downloadInterruptReason: null property url downloadUrl: "" property string suggestedFileName: "" + property string downloadDirectory: "" + property string downloadFileName: "" + property string downloadedPath: "" + property int downloadDirectoryChanged: 0 + property int downloadFileNameChanged: 0 + property int downloadPathChanged: 0 function urlToPath(url) { var path = url.toString() @@ -68,23 +74,36 @@ TestWebEngineView { ignoreUnknownSignals: true onStateChanged: downloadState.push(target.state) onInterruptReasonChanged: downloadInterruptReason = target.interruptReason + onDownloadDirectoryChanged: downloadDirectoryChanged++ + onDownloadFileNameChanged: downloadFileNameChanged++ + onPathChanged: downloadPathChanged++ } WebEngineProfile { id: testDownloadProfile onDownloadRequested: { + testDownloadProfile.downloadPath = urlToPath(StandardPaths.writableLocation(StandardPaths.TempLocation)) downloadState.push(download.state) downloadItemConnections.target = download if (cancelDownload) { download.cancel() } else { totalBytes = download.totalBytes - download.path = "testfile.zip" + download.downloadDirectory = testDownloadProfile.downloadPath + download.downloadFileName = "testfile.zip" + + if (downloadDirectory.length != 0) + download.downloadDirectory = testDownloadProfile.downloadPath + downloadDirectory + + if (downloadFileName.length != 0) + download.downloadFileName = downloadFileName + download.accept() } downloadUrl = download.url suggestedFileName = download.suggestedFileName + downloadedPath = download.downloadDirectory + download.downloadFileName } onDownloadFinished: { receivedBytes = download.receivedBytes; @@ -103,6 +122,9 @@ TestWebEngineView { downloadItemConnections.target = null downloadState = [] downloadInterruptReason = null + downloadDirectoryChanged = 0 + downloadFileNameChanged = 0 + downloadPathChanged = 0 } function test_downloadRequest() { @@ -165,5 +187,28 @@ TestWebEngineView { testDownloadProfile.downloadPath = downloadPath; compare(testDownloadProfile.downloadPath, downloadPath); } + + function test_downloadToDirectoryWithFileName() { + compare(downLoadRequestedSpy.count, 0); + compare(downloadDirectoryChanged, 0); + compare(downloadFileNameChanged, 0); + downloadDirectory = "/test/"; + downloadFileName = "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 + downloadDirectory + downloadFileName); + compare(downloadDirectoryChanged, 1); + compare(downloadFileNameChanged, 3); + compare(downloadPathChanged, 4); + downloadFinishedSpy.wait(); + compare(totalBytes, receivedBytes); + tryCompare(downloadState, "2", WebEngineDownloadItem.DownloadCompleted); + verify(!downloadInterruptReason); + } } } -- cgit v1.2.3