diff options
author | Tamas Zakor <ztamas@inf.u-szeged.hu> | 2019-05-28 13:54:28 +0200 |
---|---|---|
committer | Tamas Zakor <ztamas@inf.u-szeged.hu> | 2019-07-05 08:57:30 +0200 |
commit | 0884fab3b161b62c1e2bb1bac6bbd74560f06232 (patch) | |
tree | ec07c0b9473c5eb05880cd1783ca11dd5bc09aa0 /tests/auto/quick/qmltests | |
parent | fbc2700180d97d9c84b079b7c4da9eace19abf23 (diff) |
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 <allan.jensen@qt.io>
Diffstat (limited to 'tests/auto/quick/qmltests')
-rw-r--r-- | tests/auto/quick/qmltests/data/tst_download.qml | 47 |
1 files changed, 46 insertions, 1 deletions
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); + } } } |