summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBalazs Egedi <egedib@inf.u-szeged.hu>2021-05-05 14:23:38 +0200
committerBalazs Egedi <egedib@inf.u-szeged.hu>2021-05-07 01:31:58 +0200
commit2250a262fa3ecc68706e5e5905d44c3c04a482a9 (patch)
tree19e5561d70b0c9d226ebebd8de84c1b7325296e1
parenta5c7b4d4f16574e35ce36550bda2d45baf345c79 (diff)
Fix QWebEngineDownloadRequest signals
downloadFileNameChanged and downloadDirectoryChanged signals were removed in 08375ee7 Rename QWebEngineDownloadItem -> QWebEngineDownloadRequest. Reintroduce these signals because they are still part of the API. Also test these in Widgets auto test. QQuickWebEngineDownloadItem::pathChanged were also removed in 75393077 Remove obsolete, deprecated api from qwebenginedownloaditem. Remove the pathChanged signal checks from the test because it was deprecated. The test tst_download.qml does not have quickcontrols1 dependency. Update it in the project file and re-enable the test. Change-Id: I702e04dfe2179beafc558a628bfa07f4090fede2 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
-rw-r--r--src/core/api/qwebenginedownloadrequest.cpp18
-rw-r--r--tests/auto/quick/qmltests/data/tst_download.qml33
-rw-r--r--tests/auto/quick/qmltests/qmltests.pro2
-rw-r--r--tests/auto/widgets/qwebenginedownloadrequest/tst_qwebenginedownloadrequest.cpp10
4 files changed, 23 insertions, 40 deletions
diff --git a/src/core/api/qwebenginedownloadrequest.cpp b/src/core/api/qwebenginedownloadrequest.cpp
index 58f02ee4f..eae48b017 100644
--- a/src/core/api/qwebenginedownloadrequest.cpp
+++ b/src/core/api/qwebenginedownloadrequest.cpp
@@ -516,13 +516,20 @@ void QWebEngineDownloadRequest::setDownloadDirectory(const QString &directory)
return;
}
- if (!directory.isEmpty() && d->downloadDirectory != directory)
+ if (!directory.isEmpty() && d->downloadDirectory != directory) {
d->downloadDirectory = directory;
+ Q_EMIT downloadDirectoryChanged();
+ }
- if (!d->isCustomFileName && d->m_profileAdapter)
- d->downloadFileName = QFileInfo(d->m_profileAdapter->determineDownloadPath(d->downloadDirectory,
- d->suggestedFileName,
- d->startTime)).fileName();
+ if (!d->isCustomFileName && d->m_profileAdapter) {
+ QString newFileName = QFileInfo(d->m_profileAdapter->determineDownloadPath(d->downloadDirectory,
+ d->suggestedFileName,
+ d->startTime)).fileName();
+ if (d->downloadFileName != newFileName) {
+ d->downloadFileName = newFileName;
+ Q_EMIT downloadFileNameChanged();
+ }
+ }
}
/*!
@@ -554,6 +561,7 @@ void QWebEngineDownloadRequest::setDownloadFileName(const QString &fileName)
if (!fileName.isEmpty()) {
d->downloadFileName = fileName;
d->isCustomFileName = true;
+ Q_EMIT downloadFileNameChanged();
}
}
diff --git a/tests/auto/quick/qmltests/data/tst_download.qml b/tests/auto/quick/qmltests/data/tst_download.qml
index 894bb018a..a26060046 100644
--- a/tests/auto/quick/qmltests/data/tst_download.qml
+++ b/tests/auto/quick/qmltests/data/tst_download.qml
@@ -51,7 +51,6 @@ TestWebEngineView {
property string downloadedSetPath: ""
property int downloadDirectoryChanged: 0
property int downloadFileNameChanged: 0
- property int downloadPathChanged: 0
property bool setDirectoryFirst: false
TempDir { id: tempDir }
@@ -92,9 +91,6 @@ TestWebEngineView {
function onDownloadFileNameChanged() {
downloadFileNameChanged++;
}
- function onPathChanged() {
- downloadPathChanged++;
- }
}
WebEngineProfile {
@@ -149,7 +145,6 @@ TestWebEngineView {
downloadInterruptReason = null
downloadDirectoryChanged = 0
downloadFileNameChanged = 0
- downloadPathChanged = 0
downloadDirectory = ""
downloadFileName = ""
downloadedPath = ""
@@ -245,7 +240,6 @@ TestWebEngineView {
compare(downloadedPath, testDownloadProfile.downloadPath + downloadDirectory + downloadFileName);
compare(downloadDirectoryChanged, 1);
compare(downloadFileNameChanged, 1);
- compare(downloadPathChanged, 2);
downloadFinishedSpy.wait();
compare(totalBytes, receivedBytes);
tryCompare(downloadState, "2", WebEngineDownloadRequest.DownloadCompleted);
@@ -268,7 +262,6 @@ TestWebEngineView {
compare(downloadedPath, testDownloadProfile.downloadPath + downloadDirectory + "download.zip");
compare(downloadDirectoryChanged, 1);
compare(downloadFileNameChanged, 0);
- compare(downloadPathChanged, 1);
downloadFinishedSpy.wait();
compare(totalBytes, receivedBytes);
tryCompare(downloadState, "2", WebEngineDownloadRequest.DownloadCompleted);
@@ -280,7 +273,6 @@ TestWebEngineView {
compare(downLoadRequestedSpy.count, 0);
downloadDirectoryChanged = 0;
downloadFileNameChanged = 0;
- downloadPathChanged = 0;
downloadDirectory = "/test_downloadToDirectoryWithSuggestedFileName1/";
webEngineView.url = Qt.resolvedUrl("download.zip");
downLoadRequestedSpy.wait();
@@ -292,7 +284,6 @@ TestWebEngineView {
compare(downloadedPath, testDownloadProfile.downloadPath + downloadDirectory + "download.zip");
compare(downloadDirectoryChanged, 1);
compare(downloadFileNameChanged, 0);
- compare(downloadPathChanged, 1);
downloadFinishedSpy.wait();
compare(totalBytes, receivedBytes);
tryCompare(downloadState, "2", WebEngineDownloadRequest.DownloadCompleted);
@@ -304,7 +295,6 @@ TestWebEngineView {
compare(downLoadRequestedSpy.count, 0);
downloadDirectoryChanged = 0;
downloadFileNameChanged = 0;
- downloadPathChanged = 0;
downloadDirectory = "/test_downloadToDirectoryWithSuggestedFileName1/";
webEngineView.url = Qt.resolvedUrl("download.zip");
downLoadRequestedSpy.wait();
@@ -316,29 +306,6 @@ TestWebEngineView {
compare(downloadedPath, testDownloadProfile.downloadPath + downloadDirectory + "download (1).zip");
compare(downloadDirectoryChanged, 1);
compare(downloadFileNameChanged, 1);
- compare(downloadPathChanged, 1);
- downloadFinishedSpy.wait();
- compare(totalBytes, receivedBytes);
- tryCompare(downloadState, "2", WebEngineDownloadRequest.DownloadCompleted);
- verify(!downloadInterruptReason);
-}
-
- function test_downloadWithSetPath() {
- compare(downLoadRequestedSpy.count, 0);
- compare(downloadDirectoryChanged, 0);
- compare(downloadFileNameChanged, 0);
- downloadedSetPath = "/test_downloadWithSetPath/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], WebEngineDownloadRequest.DownloadRequested);
- tryCompare(downloadState, "1", WebEngineDownloadRequest.DownloadInProgress);
- compare(downloadedPath, testDownloadProfile.downloadPath + downloadedSetPath);
- compare(downloadDirectoryChanged, 1);
- compare(downloadFileNameChanged, 1);
- compare(downloadPathChanged, 2);
downloadFinishedSpy.wait();
compare(totalBytes, receivedBytes);
tryCompare(downloadState, "2", WebEngineDownloadRequest.DownloadCompleted);
diff --git a/tests/auto/quick/qmltests/qmltests.pro b/tests/auto/quick/qmltests/qmltests.pro
index 984d41064..e5e84d3c7 100644
--- a/tests/auto/quick/qmltests/qmltests.pro
+++ b/tests/auto/quick/qmltests/qmltests.pro
@@ -12,6 +12,7 @@ QML_TESTS = \
$$PWD/data/tst_activeFocusOnPress.qml \
$$PWD/data/tst_audioMuted.qml \
$$PWD/data/tst_desktopBehaviorLoadHtml.qml \
+ $$PWD/data/tst_download.qml \
$$PWD/data/tst_findText.qml \
$$PWD/data/tst_focusOnNavigation.qml \
$$PWD/data/tst_fullScreenRequest.qml \
@@ -81,7 +82,6 @@ qtConfig(webenginequick-testsupport) {
qtHaveModule(quickcontrols) {
QML_TESTS += \
$$PWD/data/tst_contextMenu.qml \
- $$PWD/data/tst_download.qml \
$$PWD/data/tst_filePicker.qml
}
diff --git a/tests/auto/widgets/qwebenginedownloadrequest/tst_qwebenginedownloadrequest.cpp b/tests/auto/widgets/qwebenginedownloadrequest/tst_qwebenginedownloadrequest.cpp
index 545f062c1..a69ceaed0 100644
--- a/tests/auto/widgets/qwebenginedownloadrequest/tst_qwebenginedownloadrequest.cpp
+++ b/tests/auto/widgets/qwebenginedownloadrequest/tst_qwebenginedownloadrequest.cpp
@@ -1147,20 +1147,28 @@ void tst_QWebEngineDownloadRequest::downloadToDirectoryWithFileName()
// Set up profile and download handler
ScopedConnection sc2 = connect(m_profile, &QWebEngineProfile::downloadRequested, [&](QWebEngineDownloadRequest *item) {
-
+ QSignalSpy fileNameSpy(item, &QWebEngineDownloadRequest::downloadFileNameChanged);
+ QSignalSpy directorySpy(item, &QWebEngineDownloadRequest::downloadDirectoryChanged);
+ bool isUniquifiedFileName = false;
if (!downloadDirectory.isEmpty() && setDirectoryFirst) {
+ const QString &originalFileName = item->downloadFileName();
item->setDownloadDirectory(downloadDirectory);
QCOMPARE(item->downloadDirectory(), downloadDirectory);
+ QCOMPARE(directorySpy.count(), 1);
+ isUniquifiedFileName = (originalFileName != item->downloadFileName());
+ QCOMPARE(fileNameSpy.count(), isUniquifiedFileName ? 1 : 0);
}
if (!downloadFileName.isEmpty()) {
item->setDownloadFileName(downloadFileName);
QCOMPARE(item->downloadFileName(), downloadFileName);
+ QCOMPARE(fileNameSpy.count(), isUniquifiedFileName ? 2 : 1);
}
if (!downloadDirectory.isEmpty() && !setDirectoryFirst) {
item->setDownloadDirectory(downloadDirectory);
QCOMPARE(item->downloadDirectory(), downloadDirectory);
+ QCOMPARE(directorySpy.count(), 1);
}
item->accept();