summaryrefslogtreecommitdiffstats
path: root/tests/auto/widgets/qwebenginedownloads/tst_qwebenginedownloads.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/widgets/qwebenginedownloads/tst_qwebenginedownloads.cpp')
-rw-r--r--tests/auto/widgets/qwebenginedownloads/tst_qwebenginedownloads.cpp125
1 files changed, 87 insertions, 38 deletions
diff --git a/tests/auto/widgets/qwebenginedownloads/tst_qwebenginedownloads.cpp b/tests/auto/widgets/qwebenginedownloads/tst_qwebenginedownloads.cpp
index 606fe5b12..992254206 100644
--- a/tests/auto/widgets/qwebenginedownloads/tst_qwebenginedownloads.cpp
+++ b/tests/auto/widgets/qwebenginedownloads/tst_qwebenginedownloads.cpp
@@ -60,6 +60,8 @@ private Q_SLOTS:
void downloadPage_data();
void downloadPage();
void downloadViaSetUrl();
+ void downloadFileNot1();
+ void downloadFileNot2();
};
enum DownloadTestUserAction {
@@ -86,7 +88,6 @@ void tst_QWebEngineDownloads::downloadLink_data()
QTest::addColumn<QByteArray>("fileDisposition");
QTest::addColumn<bool>("fileHasReferer");
QTest::addColumn<DownloadTestFileAction>("fileAction");
- QTest::addColumn<QWebEngineDownloadItem::DownloadType>("downloadType");
// SaveLink should always trigger a download, even for empty files.
QTest::newRow("save link to empty file")
@@ -98,8 +99,7 @@ void tst_QWebEngineDownloads::downloadLink_data()
/* fileMimeTypeDetected */ << QByteArrayLiteral("")
/* fileDisposition */ << QByteArrayLiteral("")
/* fileHasReferer */ << true
- /* fileAction */ << FileIsDownloaded
- /* downloadType */ << QWebEngineDownloadItem::UserRequested;
+ /* fileAction */ << FileIsDownloaded;
// SaveLink should always trigger a download, also for text files.
QTest::newRow("save link to text file")
@@ -111,8 +111,7 @@ void tst_QWebEngineDownloads::downloadLink_data()
/* fileMimeTypeDetected */ << QByteArrayLiteral("text/plain")
/* fileDisposition */ << QByteArrayLiteral("")
/* fileHasReferer */ << true
- /* fileAction */ << FileIsDownloaded
- /* downloadType */ << QWebEngineDownloadItem::UserRequested;
+ /* fileAction */ << FileIsDownloaded;
// ... adding the "download" attribute should have no effect.
QTest::newRow("save link to text file (attribute)")
@@ -124,8 +123,7 @@ void tst_QWebEngineDownloads::downloadLink_data()
/* fileMimeTypeDetected */ << QByteArrayLiteral("text/plain")
/* fileDisposition */ << QByteArrayLiteral("")
/* fileHasReferer */ << true
- /* fileAction */ << FileIsDownloaded
- /* downloadType */ << QWebEngineDownloadItem::UserRequested;
+ /* fileAction */ << FileIsDownloaded;
// ... adding the "attachment" content disposition should also have no effect.
QTest::newRow("save link to text file (attachment)")
@@ -137,8 +135,7 @@ void tst_QWebEngineDownloads::downloadLink_data()
/* fileMimeTypeDetected */ << QByteArrayLiteral("text/plain")
/* fileDisposition */ << QByteArrayLiteral("attachment")
/* fileHasReferer */ << true
- /* fileAction */ << FileIsDownloaded
- /* downloadType */ << QWebEngineDownloadItem::UserRequested;
+ /* fileAction */ << FileIsDownloaded;
// ... even adding both should have no effect.
QTest::newRow("save link to text file (attribute+attachment)")
@@ -150,8 +147,7 @@ void tst_QWebEngineDownloads::downloadLink_data()
/* fileMimeTypeDetected */ << QByteArrayLiteral("text/plain")
/* fileDisposition */ << QByteArrayLiteral("attachment")
/* fileHasReferer */ << true
- /* fileAction */ << FileIsDownloaded
- /* downloadType */ << QWebEngineDownloadItem::UserRequested;
+ /* fileAction */ << FileIsDownloaded;
// Navigating to an empty file should show an empty page.
QTest::newRow("navigate to empty file")
@@ -163,8 +159,7 @@ void tst_QWebEngineDownloads::downloadLink_data()
/* fileMimeTypeDetected */ << QByteArrayLiteral("")
/* fileDisposition */ << QByteArrayLiteral("")
/* fileHasReferer */ << true
- /* fileAction */ << FileIsDisplayed
- /* downloadType */ << /* unused */ QWebEngineDownloadItem::DownloadAttribute;
+ /* fileAction */ << FileIsDisplayed;
// Navigating to a text file should show the text file.
QTest::newRow("navigate to text file")
@@ -176,8 +171,7 @@ void tst_QWebEngineDownloads::downloadLink_data()
/* fileMimeTypeDetected */ << QByteArrayLiteral("text/plain")
/* fileDisposition */ << QByteArrayLiteral("")
/* fileHasReferer */ << true
- /* fileAction */ << FileIsDisplayed
- /* downloadType */ << /* unused */ QWebEngineDownloadItem::DownloadAttribute;
+ /* fileAction */ << FileIsDisplayed;
// ... unless the link has the "download" attribute: then the file should be downloaded.
QTest::newRow("navigate to text file (attribute)")
@@ -189,8 +183,7 @@ void tst_QWebEngineDownloads::downloadLink_data()
/* fileMimeTypeDetected */ << QByteArrayLiteral("text/plain")
/* fileDisposition */ << QByteArrayLiteral("")
/* fileHasReferer */ << false // crbug.com/455987
- /* fileAction */ << FileIsDownloaded
- /* downloadType */ << QWebEngineDownloadItem::DownloadAttribute;
+ /* fileAction */ << FileIsDownloaded;
// ... same with the content disposition header save for the download type.
QTest::newRow("navigate to text file (attachment)")
@@ -202,8 +195,7 @@ void tst_QWebEngineDownloads::downloadLink_data()
/* fileMimeTypeDetected */ << QByteArrayLiteral("text/plain")
/* fileDisposition */ << QByteArrayLiteral("attachment")
/* fileHasReferer */ << true
- /* fileAction */ << FileIsDownloaded
- /* downloadType */ << QWebEngineDownloadItem::Attachment;
+ /* fileAction */ << FileIsDownloaded;
// ... and both.
QTest::newRow("navigate to text file (attribute+attachment)")
@@ -215,8 +207,7 @@ void tst_QWebEngineDownloads::downloadLink_data()
/* fileMimeTypeDetected */ << QByteArrayLiteral("text/plain")
/* fileDisposition */ << QByteArrayLiteral("attachment")
/* fileHasReferer */ << false // crbug.com/455987
- /* fileAction */ << FileIsDownloaded
- /* downloadType */ << QWebEngineDownloadItem::Attachment;
+ /* fileAction */ << FileIsDownloaded;
// The file's extension has no effect.
QTest::newRow("navigate to supposed zip file")
@@ -228,8 +219,7 @@ void tst_QWebEngineDownloads::downloadLink_data()
/* fileMimeTypeDetected */ << QByteArrayLiteral("")
/* fileDisposition */ << QByteArrayLiteral("")
/* fileHasReferer */ << true
- /* fileAction */ << FileIsDisplayed
- /* downloadType */ << /* unused */ QWebEngineDownloadItem::DownloadAttribute;
+ /* fileAction */ << FileIsDisplayed;
// ... the file's mime type however does.
QTest::newRow("navigate to supposed zip file (application/zip)")
@@ -241,8 +231,7 @@ void tst_QWebEngineDownloads::downloadLink_data()
/* fileMimeTypeDetected */ << QByteArrayLiteral("application/zip")
/* fileDisposition */ << QByteArrayLiteral("")
/* fileHasReferer */ << true
- /* fileAction */ << FileIsDownloaded
- /* downloadType */ << QWebEngineDownloadItem::DownloadAttribute;
+ /* fileAction */ << FileIsDownloaded;
// ... but we're not very picky about the exact type.
QTest::newRow("navigate to supposed zip file (application/octet-stream)")
@@ -254,8 +243,7 @@ void tst_QWebEngineDownloads::downloadLink_data()
/* fileMimeTypeDetected */ << QByteArrayLiteral("application/octet-stream")
/* fileDisposition */ << QByteArrayLiteral("")
/* fileHasReferer */ << true
- /* fileAction */ << FileIsDownloaded
- /* downloadType */ << QWebEngineDownloadItem::DownloadAttribute;
+ /* fileAction */ << FileIsDownloaded;
// empty zip file (consisting only of "end of central directory record")
QByteArray zipFile = QByteArrayLiteral("PK\x05\x06") + QByteArray(18, 0);
@@ -270,8 +258,7 @@ void tst_QWebEngineDownloads::downloadLink_data()
/* fileMimeTypeDetected */ << QByteArrayLiteral("application/octet-stream")
/* fileDisposition */ << QByteArrayLiteral("")
/* fileHasReferer */ << true
- /* fileAction */ << FileIsDownloaded
- /* downloadType */ << QWebEngineDownloadItem::DownloadAttribute;
+ /* fileAction */ << FileIsDownloaded;
// The mime type is not guessed automatically if provided by the server.
QTest::newRow("navigate to actual zip file (application/zip)")
@@ -283,8 +270,7 @@ void tst_QWebEngineDownloads::downloadLink_data()
/* fileMimeTypeDetected */ << QByteArrayLiteral("application/zip")
/* fileDisposition */ << QByteArrayLiteral("")
/* fileHasReferer */ << true
- /* fileAction */ << FileIsDownloaded
- /* downloadType */ << QWebEngineDownloadItem::DownloadAttribute;
+ /* fileAction */ << FileIsDownloaded;
}
void tst_QWebEngineDownloads::downloadLink()
@@ -298,7 +284,6 @@ void tst_QWebEngineDownloads::downloadLink()
QFETCH(QByteArray, fileDisposition);
QFETCH(bool, fileHasReferer);
QFETCH(DownloadTestFileAction, fileAction);
- QFETCH(QWebEngineDownloadItem::DownloadType, downloadType);
HttpServer server;
QWebEngineProfile profile;
@@ -395,7 +380,8 @@ void tst_QWebEngineDownloads::downloadLink()
QCOMPARE(item->totalBytes(), -1);
QCOMPARE(item->receivedBytes(), 0);
QCOMPARE(item->interruptReason(), QWebEngineDownloadItem::NoReason);
- QCOMPARE(item->type(), downloadType);
+ QCOMPARE(item->type(), QWebEngineDownloadItem::UserRequested);
+ QCOMPARE(item->isSavePageDownload(), false);
QCOMPARE(item->mimeType(), QString(fileMimeTypeDetected));
QCOMPARE(item->path(), suggestedPath);
QCOMPARE(item->savePageFormat(), QWebEngineDownloadItem::UnknownSaveFormat);
@@ -413,7 +399,8 @@ void tst_QWebEngineDownloads::downloadLink()
QCOMPARE(item->totalBytes(), fileContents.size());
QCOMPARE(item->receivedBytes(), fileContents.size());
QCOMPARE(item->interruptReason(), QWebEngineDownloadItem::NoReason);
- QCOMPARE(item->type(), downloadType);
+ QCOMPARE(item->type(), QWebEngineDownloadItem::UserRequested);
+ QCOMPARE(item->isSavePageDownload(), false);
QCOMPARE(item->mimeType(), QString(fileMimeTypeDetected));
QCOMPARE(item->path(), downloadPath);
QCOMPARE(item->savePageFormat(), QWebEngineDownloadItem::UnknownSaveFormat);
@@ -498,7 +485,6 @@ void tst_QWebEngineDownloads::downloadTwoLinks()
QCOMPARE(item->totalBytes(), -1);
QCOMPARE(item->receivedBytes(), 0);
QCOMPARE(item->interruptReason(), QWebEngineDownloadItem::NoReason);
- QCOMPARE(item->type(), QWebEngineDownloadItem::DownloadAttribute);
QCOMPARE(item->mimeType(), QStringLiteral("text/plain"));
QCOMPARE(item->path(), standardDir + QByteArrayLiteral("/file1"));
QCOMPARE(item->savePageFormat(), QWebEngineDownloadItem::UnknownSaveFormat);
@@ -517,7 +503,6 @@ void tst_QWebEngineDownloads::downloadTwoLinks()
QCOMPARE(item->totalBytes(), -1);
QCOMPARE(item->receivedBytes(), 0);
QCOMPARE(item->interruptReason(), QWebEngineDownloadItem::NoReason);
- QCOMPARE(item->type(), QWebEngineDownloadItem::Attachment);
QCOMPARE(item->mimeType(), QStringLiteral("text/plain"));
QCOMPARE(item->path(), standardDir + QByteArrayLiteral("/file2"));
QCOMPARE(item->savePageFormat(), QWebEngineDownloadItem::UnknownSaveFormat);
@@ -578,6 +563,7 @@ void tst_QWebEngineDownloads::downloadPage()
QCOMPARE(item->receivedBytes(), 0);
QCOMPARE(item->interruptReason(), QWebEngineDownloadItem::NoReason);
QCOMPARE(item->type(), QWebEngineDownloadItem::SavePage);
+ QCOMPARE(item->isSavePageDownload(), true);
// FIXME why is mimeType always the same?
QCOMPARE(item->mimeType(), QStringLiteral("application/x-mimearchive"));
QCOMPARE(item->path(), downloadPath);
@@ -596,6 +582,7 @@ void tst_QWebEngineDownloads::downloadPage()
QVERIFY(item->receivedBytes() > 0);
QCOMPARE(item->interruptReason(), QWebEngineDownloadItem::NoReason);
QCOMPARE(item->type(), QWebEngineDownloadItem::SavePage);
+ QCOMPARE(item->isSavePageDownload(), true);
QCOMPARE(item->mimeType(), QStringLiteral("application/x-mimearchive"));
QCOMPARE(item->path(), downloadPath);
QCOMPARE(item->savePageFormat(), savePageFormat);
@@ -635,6 +622,8 @@ void tst_QWebEngineDownloads::downloadViaSetUrl()
auto indexFavRR = waitForFaviconRequest(&server);
QVERIFY(indexFavRR);
+ indexRR.reset();
+ indexFavRR.reset();
QTRY_COMPARE(loadSpy.count(), 1);
QTRY_COMPARE(urlSpy.count(), 1);
@@ -655,16 +644,20 @@ void tst_QWebEngineDownloads::downloadViaSetUrl()
auto fileRR = waitForRequest(&server);
QVERIFY(fileRR);
+ QCOMPARE(fileRR->requestMethod(), QByteArrayLiteral("GET"));
+ QCOMPARE(fileRR->requestPath(), QByteArrayLiteral("/file"));
fileRR->setResponseHeader(QByteArrayLiteral("content-disposition"), QByteArrayLiteral("attachment"));
fileRR->setResponseBody(QByteArrayLiteral("redacted"));
fileRR->sendResponse();
- auto fileFavRR = waitForFaviconRequest(&server);
- QVERIFY(fileFavRR);
+// Since 63 we no longer get favicon requests here:
+// auto fileFavRR = waitForFaviconRequest(&server);
+// QVERIFY(fileFavRR);
QTRY_COMPARE(loadSpy.count(), 1);
QTRY_COMPARE(urlSpy.count(), 2);
QTRY_COMPARE(downloadUrls.count(), 1);
+ fileRR.reset();
QCOMPARE(loadSpy.takeFirst().value(0).toBool(), false);
QCOMPARE(urlSpy.takeFirst().value(0).toUrl(), fileUrl);
QCOMPARE(urlSpy.takeFirst().value(0).toUrl(), indexUrl);
@@ -673,5 +666,61 @@ void tst_QWebEngineDownloads::downloadViaSetUrl()
}
}
+void tst_QWebEngineDownloads::downloadFileNot1()
+{
+ // Trigger file download via download() but don't accept().
+
+ HttpServer server;
+ QWebEngineProfile profile;
+ QWebEnginePage page(&profile);
+ const auto filePath = QByteArrayLiteral("/file");
+ const auto fileUrl = server.url(filePath);
+
+ page.download(fileUrl);
+ auto fileRR = waitForRequest(&server);
+ QVERIFY(fileRR);
+ QCOMPARE(fileRR->requestMethod(), QByteArrayLiteral("GET"));
+ QCOMPARE(fileRR->requestPath(), filePath);
+ fileRR->sendResponse();
+
+ QPointer<QWebEngineDownloadItem> downloadItem;
+ QVERIFY(waitForSignal(&profile, &QWebEngineProfile::downloadRequested,
+ [&](QWebEngineDownloadItem *item) {
+ QVERIFY(item);
+ QCOMPARE(item->state(), QWebEngineDownloadItem::DownloadRequested);
+ downloadItem = item;
+ }));
+ QVERIFY(!downloadItem);
+}
+
+void tst_QWebEngineDownloads::downloadFileNot2()
+{
+ // Trigger file download via download() but call cancel() instead of accept().
+
+ HttpServer server;
+ QWebEngineProfile profile;
+ QWebEnginePage page(&profile);
+ const auto filePath = QByteArrayLiteral("/file");
+ const auto fileUrl = server.url(filePath);
+
+ page.download(fileUrl);
+ auto fileRR = waitForRequest(&server);
+ QVERIFY(fileRR);
+ QCOMPARE(fileRR->requestMethod(), QByteArrayLiteral("GET"));
+ QCOMPARE(fileRR->requestPath(), filePath);
+ fileRR->sendResponse();
+
+ QPointer<QWebEngineDownloadItem> downloadItem;
+ QVERIFY(waitForSignal(&profile, &QWebEngineProfile::downloadRequested,
+ [&](QWebEngineDownloadItem *item) {
+ QVERIFY(item);
+ QCOMPARE(item->state(), QWebEngineDownloadItem::DownloadRequested);
+ item->cancel();
+ downloadItem = item;
+ }));
+ QVERIFY(downloadItem);
+ QCOMPARE(downloadItem->state(), QWebEngineDownloadItem::DownloadCancelled);
+}
+
QTEST_MAIN(tst_QWebEngineDownloads)
#include "tst_qwebenginedownloads.moc"