summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorMichael BrĂ¼ning <michael.bruning@qt.io>2021-01-18 16:03:25 +0100
committerMichael BrĂ¼ning <michael.bruning@qt.io>2021-01-22 15:05:17 +0100
commita134b801dc38feb536d4829213624dba72702d54 (patch)
tree1adf4907861cbaf4a7b01c895a90b521dfaf0aa8 /tests/auto
parent91b3a9c056af7e08aca49d8dc2393d23fe6acf85 (diff)
Do not extract download file names from certain url schemes
Chromium uses the default download file name if the scheme of a file to download is either about or data, as the file name extraction methods do not seems to work for those. Mimic this behavior in Qt WebEngine as well. Fixes: QTBUG-90355 Change-Id: I14b8c4f64559500d3f231dd26533a5947bf94bc3 Reviewed-by: Michal Klocek <michal.klocek@qt.io>
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/widgets/qwebenginedownloaditem/tst_qwebenginedownloaditem.cpp47
1 files changed, 47 insertions, 0 deletions
diff --git a/tests/auto/widgets/qwebenginedownloaditem/tst_qwebenginedownloaditem.cpp b/tests/auto/widgets/qwebenginedownloaditem/tst_qwebenginedownloaditem.cpp
index ec88fc581..9a3e7b52e 100644
--- a/tests/auto/widgets/qwebenginedownloaditem/tst_qwebenginedownloaditem.cpp
+++ b/tests/auto/widgets/qwebenginedownloaditem/tst_qwebenginedownloaditem.cpp
@@ -84,6 +84,8 @@ private Q_SLOTS:
#endif
void downloadToDirectoryWithFileName_data();
void downloadToDirectoryWithFileName();
+ void downloadDataUrls_data();
+ void downloadDataUrls();
private:
void saveLink(QPoint linkPos);
@@ -1392,5 +1394,50 @@ void tst_QWebEngineDownloadItem::downloadToDirectoryWithFileName()
QCOMPARE(downloadedSuggestedFileName, fileName);
}
+void tst_QWebEngineDownloadItem::downloadDataUrls_data()
+{
+ QTest::addColumn<QByteArray>("htmlData");
+ QTest::addColumn<QString>("expectedFileName");
+ QTest::newRow("data url without slash") << QByteArrayLiteral("<html><head><meta charset=\"utf-8\"></head><body><a href=\"data:application/gzip;base64,dGVzdA==\">data URL without slash</a><br/></body></html>") << QStringLiteral("qwe_download.gz") ;
+ QTest::newRow("data url with slash") << QByteArrayLiteral("<html><head><meta charset=\"utf-8\"></head><body><a href=\"data:application/gzip;base64,dGVzcnI/dGVzdA==\">data URL with filename</a><br/></body></html>") << QStringLiteral("qwe_download.gz") ;
+ QTest::newRow("data url with download tag") << QByteArrayLiteral("<html><head><meta charset=\"utf-8\"></head><body><a href=\"data:application/gzip;base64,dGVzdA/IHRlc3Q=\" download=\"filename.gz\">data URL with filename</a><br/></body></html>") << QStringLiteral("filename.gz") ;
+
+}
+
+void tst_QWebEngineDownloadItem::downloadDataUrls()
+{
+ QFETCH(QByteArray, htmlData);
+ QFETCH(QString, expectedFileName);
+ // Set up HTTP server
+ ScopedConnection sc1 = connect(m_server, &HttpServer::newRequest, [&](HttpReqRep *rr) {
+ if (rr->requestMethod() == "GET" && rr->requestPath() == "/") {
+ rr->setResponseHeader(QByteArrayLiteral("content-type"), QByteArrayLiteral("text/html"));
+ rr->setResponseBody(htmlData);
+ rr->sendResponse();
+ }
+ });
+
+ // Set up profile and download handler
+ QTemporaryDir tmpDir;
+ QVERIFY(tmpDir.isValid());
+ m_profile->setDownloadPath(tmpDir.path());
+
+ int downloadRequestCount = 0;
+ ScopedConnection sc2 = connect(m_profile, &QWebEngineProfile::downloadRequested, [&](QWebEngineDownloadItem *item) {
+ QCOMPARE(item->state(), QWebEngineDownloadItem::DownloadRequested);
+ QCOMPARE(item->downloadFileName(), expectedFileName);
+ downloadRequestCount++;
+ });
+
+ QSignalSpy loadSpy(m_page, &QWebEnginePage::loadFinished);
+ m_view->load(m_server->url());
+ QTRY_COMPARE(loadSpy.count(), 1);
+ QCOMPARE(loadSpy.takeFirst().value(0).toBool(), true);
+
+ // Trigger download
+ simulateUserAction(QPoint(10, 10), UserAction::ClickLink);
+ QTRY_COMPARE(downloadRequestCount, 1);
+}
+
QTEST_MAIN(tst_QWebEngineDownloadItem)
#include "tst_qwebenginedownloaditem.moc"