summaryrefslogtreecommitdiffstats
path: root/tests/auto/widgets
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2021-02-01 17:14:20 +0100
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2021-02-02 16:31:06 +0100
commit76835d39323731af1b784ca3ca588d1d9e8a0086 (patch)
treef5b443d692ded7ede89c80fa0e6804759aa5684b /tests/auto/widgets
parentcde72003881c6b5680ac8ac0fe6d6971bb43e0d5 (diff)
parentbbf2c566d2804a8ff73c5896e7b2db31c958f1c4 (diff)
Merge remote-tracking branch 'origin/5.15' into dev
Conflicts: tests/auto/widgets/qwebenginedownloadrequest/tst_qwebenginedownloadrequest.cpp Change-Id: Ibf03467e398f8dcdb5f950e1a70f3e4e591003db
Diffstat (limited to 'tests/auto/widgets')
-rw-r--r--tests/auto/widgets/qwebenginedownloadrequest/tst_qwebenginedownloadrequest.cpp47
1 files changed, 47 insertions, 0 deletions
diff --git a/tests/auto/widgets/qwebenginedownloadrequest/tst_qwebenginedownloadrequest.cpp b/tests/auto/widgets/qwebenginedownloadrequest/tst_qwebenginedownloadrequest.cpp
index 3c3f1054d..545f062c1 100644
--- a/tests/auto/widgets/qwebenginedownloadrequest/tst_qwebenginedownloadrequest.cpp
+++ b/tests/auto/widgets/qwebenginedownloadrequest/tst_qwebenginedownloadrequest.cpp
@@ -81,6 +81,8 @@ private Q_SLOTS:
void downloadToReadOnlyDir();
void downloadToDirectoryWithFileName_data();
void downloadToDirectoryWithFileName();
+ void downloadDataUrls_data();
+ void downloadDataUrls();
private:
void saveLink(QPoint linkPos);
@@ -1249,5 +1251,50 @@ void tst_QWebEngineDownloadRequest::downloadToDirectoryWithFileName()
QCOMPARE(downloadedSuggestedFileName, fileName);
}
+void tst_QWebEngineDownloadRequest::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_QWebEngineDownloadRequest::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, [&](QWebEngineDownloadRequest *item) {
+ QCOMPARE(item->state(), QWebEngineDownloadRequest::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_QWebEngineDownloadRequest)
#include "tst_qwebenginedownloadrequest.moc"