diff options
Diffstat (limited to 'tests/auto/widgets/qwebenginedownloaditem/tst_qwebenginedownloaditem.cpp')
-rw-r--r-- | tests/auto/widgets/qwebenginedownloaditem/tst_qwebenginedownloaditem.cpp | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/tests/auto/widgets/qwebenginedownloaditem/tst_qwebenginedownloaditem.cpp b/tests/auto/widgets/qwebenginedownloaditem/tst_qwebenginedownloaditem.cpp index bc474457a..02b46bc6b 100644 --- a/tests/auto/widgets/qwebenginedownloaditem/tst_qwebenginedownloaditem.cpp +++ b/tests/auto/widgets/qwebenginedownloaditem/tst_qwebenginedownloaditem.cpp @@ -869,6 +869,7 @@ void tst_QWebEngineDownloadItem::downloadUniqueFilename() QFETCH(QString, extension); QString fileName = QString("%1.%2").arg(baseName).arg(extension); QString downloadedFilePath; + QString suggestedFileName; bool downloadFinished = false; QTemporaryDir tmpDir; @@ -890,6 +891,7 @@ void tst_QWebEngineDownloadItem::downloadUniqueFilename() // Set up profile and download handler ScopedConnection sc2 = connect(m_profile, &QWebEngineProfile::downloadRequested, [&](QWebEngineDownloadItem *item) { + suggestedFileName = item->suggestedFileName(); item->accept(); connect(item, &QWebEngineDownloadItem::finished, [&, item]() { QCOMPARE(item->state(), QWebEngineDownloadItem::DownloadCompleted); @@ -915,6 +917,7 @@ void tst_QWebEngineDownloadItem::downloadUniqueFilename() QTRY_VERIFY(downloadFinished); QVERIFY(QFile(downloadedFilePath).exists()); QCOMPARE(downloadedFilePath, m_profile->downloadPath() + "/" + baseName + " (" + QString::number(i) + ")." + extension); + QCOMPARE(suggestedFileName, fileName); } } @@ -925,6 +928,7 @@ void tst_QWebEngineDownloadItem::downloadUniqueFilenameWithTimestamp() QString extension("txt"); QString fileName = QString("%1.%2").arg(baseName).arg(extension); QString downloadedFilePath; + QString suggestedFileName; bool downloadFinished = false; QTemporaryDir tmpDir; @@ -945,6 +949,7 @@ void tst_QWebEngineDownloadItem::downloadUniqueFilenameWithTimestamp() // Set up profile and download handler ScopedConnection sc2 = connect(m_profile, &QWebEngineProfile::downloadRequested, [&](QWebEngineDownloadItem *item) { + suggestedFileName = item->suggestedFileName(); item->accept(); connect(item, &QWebEngineDownloadItem::finished, [&, item]() { QCOMPARE(item->state(), QWebEngineDownloadItem::DownloadCompleted); @@ -975,6 +980,7 @@ void tst_QWebEngineDownloadItem::downloadUniqueFilenameWithTimestamp() QTRY_VERIFY(downloadFinished); QVERIFY(QFile(downloadedFilePath).exists()); QCOMPARE(downloadedFilePath, m_profile->downloadPath() + "/" + baseName + " (100)." + extension); + QCOMPARE(suggestedFileName, fileName); // Check if the downloaded files are suffixed with timestamp after the 100th download. for (int i = 101; i < 103; i++) { @@ -988,6 +994,7 @@ void tst_QWebEngineDownloadItem::downloadUniqueFilenameWithTimestamp() // ISO 8601 Date and time in UTC QRegExp timestamp("^(-?(?:[1-9][0-9]*)?[0-9]{4})-(1[0-2]|0[1-9])-(3[01]|0[1-9]|[12][0-9])T(2[0-3]|[01][0-9])([0-5][0-9])([0-5][0-9])([.][0-9]+)?(Z|[+-](?:2[0-3]|[01][0-9])[0-5][0-9])?$"); QVERIFY(timestamp.exactMatch(match.captured(1))); + QCOMPARE(suggestedFileName, fileName); } } @@ -1014,6 +1021,7 @@ void tst_QWebEngineDownloadItem::downloadToNonExistentDir() QString extension("txt"); QString fileName = QString("%1.%2").arg(baseName).arg(extension); QString downloadedFilePath; + QString suggestedFileName; bool downloadFinished = false; QTemporaryDir tmpDir; @@ -1035,6 +1043,7 @@ void tst_QWebEngineDownloadItem::downloadToNonExistentDir() // Set up profile and download handler ScopedConnection sc2 = connect(m_profile, &QWebEngineProfile::downloadRequested, [&](QWebEngineDownloadItem *item) { + suggestedFileName = item->suggestedFileName(); item->accept(); connect(item, &QWebEngineDownloadItem::finished, [&, item]() { QCOMPARE(item->state(), QWebEngineDownloadItem::DownloadCompleted); @@ -1056,6 +1065,7 @@ void tst_QWebEngineDownloadItem::downloadToNonExistentDir() QTRY_VERIFY(downloadFinished); QVERIFY(QFile(downloadedFilePath).exists()); QCOMPARE(downloadedFilePath, nonExistentDownloadPath + "/" + fileName); + QCOMPARE(suggestedFileName, fileName); } void tst_QWebEngineDownloadItem::downloadToReadOnlyDir() @@ -1067,6 +1077,7 @@ void tst_QWebEngineDownloadItem::downloadToReadOnlyDir() QString extension("txt"); QString fileName = QString("%1.%2").arg(baseName).arg(extension); QString downloadedFilePath; + QString suggestedFileName; bool downloadAccepted = false; bool downloadFinished = false; @@ -1089,6 +1100,7 @@ void tst_QWebEngineDownloadItem::downloadToReadOnlyDir() QPointer<QWebEngineDownloadItem> downloadItem; ScopedConnection sc2 = connect(m_profile, &QWebEngineProfile::downloadRequested, [&](QWebEngineDownloadItem *item) { + suggestedFileName = item->suggestedFileName(); downloadItem = item; item->accept(); connect(item, &QWebEngineDownloadItem::finished, [&, item]() { @@ -1109,6 +1121,7 @@ void tst_QWebEngineDownloadItem::downloadToReadOnlyDir() QCOMPARE(downloadItem->isFinished(), false); QCOMPARE(downloadItem->interruptReason(), QWebEngineDownloadItem::FileAccessDenied); QVERIFY(!QFile(downloadedFilePath).exists()); + QCOMPARE(suggestedFileName, fileName); // Clear m_requestedDownloads explicitly because download is accepted but never finished. m_requestedDownloads.clear(); |