summaryrefslogtreecommitdiffstats
path: root/tests/auto/widgets
diff options
context:
space:
mode:
authorKirill Burtsev <kirill.burtsev@qt.io>2019-11-28 19:10:23 +0100
committerKirill Burtsev <kirill.burtsev@qt.io>2019-11-29 10:51:14 +0100
commitc24cc3014d750a406523629eff94f4f5f87e92cb (patch)
treecfa54177e8ae32a052950b23e50b71e7d5efae3c /tests/auto/widgets
parent468c2d9a6d7b95b7dacc5372726860e7ccf14fb4 (diff)
Fix 'setDownloadDirectory' for download item on 'SavePage' action
Chromium's DownloadManager doesn't create its download items before path for saving page is confirmed. So assert inside updateDownloadPath was not correct. Moreover, the name is confusing because it's not really updating anything. Remove it and use ProfileAdapterClient::DownloadInfo timestamp to determine updated filename after directory change. Ammends recent new api for changing download directory 0884fab3b1. Fixes: QTBUG-80372 Change-Id: If9efb52979deb3cf21fc4e12989173c85e04e090 Reviewed-by: Jüri Valdmann <juri.valdmann@qt.io>
Diffstat (limited to 'tests/auto/widgets')
-rw-r--r--tests/auto/widgets/qwebenginedownloaditem/tst_qwebenginedownloaditem.cpp31
1 files changed, 23 insertions, 8 deletions
diff --git a/tests/auto/widgets/qwebenginedownloaditem/tst_qwebenginedownloaditem.cpp b/tests/auto/widgets/qwebenginedownloaditem/tst_qwebenginedownloaditem.cpp
index d34e3cefe..bbcef2226 100644
--- a/tests/auto/widgets/qwebenginedownloaditem/tst_qwebenginedownloaditem.cpp
+++ b/tests/auto/widgets/qwebenginedownloaditem/tst_qwebenginedownloaditem.cpp
@@ -622,14 +622,17 @@ void tst_QWebEngineDownloadItem::downloadTwoLinks()
void tst_QWebEngineDownloadItem::downloadPage_data()
{
+ QTest::addColumn<bool>("saveWithPageAction");
QTest::addColumn<QWebEngineDownloadItem::SavePageFormat>("savePageFormat");
- QTest::newRow("SingleHtmlSaveFormat") << QWebEngineDownloadItem::SingleHtmlSaveFormat;
- QTest::newRow("CompleteHtmlSaveFormat") << QWebEngineDownloadItem::CompleteHtmlSaveFormat;
- QTest::newRow("MimeHtmlSaveFormat") << QWebEngineDownloadItem::MimeHtmlSaveFormat;
+ QTest::newRow("SingleHtmlSaveFormat") << false << QWebEngineDownloadItem::SingleHtmlSaveFormat;
+ QTest::newRow("CompleteHtmlSaveFormat") << false << QWebEngineDownloadItem::CompleteHtmlSaveFormat;
+ QTest::newRow("MimeHtmlSaveFormat") << false << QWebEngineDownloadItem::MimeHtmlSaveFormat;
+ QTest::newRow("SavePageAction") << true << QWebEngineDownloadItem::MimeHtmlSaveFormat;
}
void tst_QWebEngineDownloadItem::downloadPage()
{
+ QFETCH(bool, saveWithPageAction);
QFETCH(QWebEngineDownloadItem::SavePageFormat, savePageFormat);
// Set up HTTP server
@@ -649,12 +652,12 @@ void tst_QWebEngineDownloadItem::downloadPage()
// Set up profile and download handler
QTemporaryDir tmpDir;
QVERIFY(tmpDir.isValid());
- QString downloadPath = tmpDir.path() + QStringLiteral("/test.html");
+ QString downloadFileName("test.html"), downloadPath = tmpDir.filePath(downloadFileName);
QUrl downloadUrl = m_server->url("/");
int acceptedCount = 0;
int finishedCount = 0;
ScopedConnection sc2 = connect(m_profile, &QWebEngineProfile::downloadRequested, [&](QWebEngineDownloadItem *item) {
- QCOMPARE(item->state(), QWebEngineDownloadItem::DownloadInProgress);
+ QCOMPARE(item->state(), saveWithPageAction ? QWebEngineDownloadItem::DownloadRequested : QWebEngineDownloadItem::DownloadInProgress);
QCOMPARE(item->isFinished(), false);
QCOMPARE(item->totalBytes(), -1);
QCOMPARE(item->receivedBytes(), 0);
@@ -663,11 +666,19 @@ void tst_QWebEngineDownloadItem::downloadPage()
QCOMPARE(item->isSavePageDownload(), true);
// FIXME(juvaldma): why is mimeType always the same?
QCOMPARE(item->mimeType(), QStringLiteral("application/x-mimearchive"));
- QCOMPARE(QDir(item->downloadDirectory()).filePath(item->downloadFileName()), downloadPath);
QCOMPARE(item->savePageFormat(), savePageFormat);
QCOMPARE(item->url(), downloadUrl);
QCOMPARE(item->page(), m_page);
- // no need to call item->accept()
+
+ if (saveWithPageAction) {
+ QVERIFY(!item->downloadDirectory().isEmpty());
+ QVERIFY(!item->downloadFileName().isEmpty());
+ item->setDownloadDirectory(tmpDir.path());
+ item->setDownloadFileName(downloadFileName);
+ item->accept();
+ } // save with explicit path accepts download automatically
+
+ QCOMPARE(QDir(item->downloadDirectory()).filePath(item->downloadFileName()), downloadPath);
connect(item, &QWebEngineDownloadItem::finished, [&, item]() {
QCOMPARE(item->state(), QWebEngineDownloadItem::DownloadCompleted);
@@ -697,7 +708,11 @@ void tst_QWebEngineDownloadItem::downloadPage()
QCOMPARE(indexRequestCount, 1);
// Save some HTML
- m_page->save(downloadPath, savePageFormat);
+ if (saveWithPageAction)
+ m_page->triggerAction(QWebEnginePage::SavePage);
+ else
+ m_page->save(downloadPath, savePageFormat);
+
QTRY_COMPARE(acceptedCount, 1);
QTRY_COMPARE(finishedCount, 1);
QFile file(downloadPath);