summaryrefslogtreecommitdiffstats
path: root/tests/auto/widgets
diff options
context:
space:
mode:
authorJüri Valdmann <juri.valdmann@qt.io>2017-08-14 13:03:19 +0200
committerJüri Valdmann <juri.valdmann@qt.io>2017-09-12 08:21:19 +0000
commit803034049b25c556c21264fc62bf2c720ba8165c (patch)
treecc0c5bfc99497879eb0f44b4889745d94375cd44 /tests/auto/widgets
parent1c7a520edfb850cc34a29d96417c475a373ed355 (diff)
Add test for two simultaneous downloads
Change-Id: I8342aa806c3d1a8f4f1a5e822ef1be0e1755220c Reviewed-by: Michal Klocek <michal.klocek@qt.io>
Diffstat (limited to 'tests/auto/widgets')
-rw-r--r--tests/auto/widgets/qwebenginedownloads/tst_qwebenginedownloads.cpp92
1 files changed, 92 insertions, 0 deletions
diff --git a/tests/auto/widgets/qwebenginedownloads/tst_qwebenginedownloads.cpp b/tests/auto/widgets/qwebenginedownloads/tst_qwebenginedownloads.cpp
index a03681cb1..b8d73f2e0 100644
--- a/tests/auto/widgets/qwebenginedownloads/tst_qwebenginedownloads.cpp
+++ b/tests/auto/widgets/qwebenginedownloads/tst_qwebenginedownloads.cpp
@@ -43,6 +43,7 @@ class tst_QWebEngineDownloads : public QObject
private Q_SLOTS:
void downloadLink_data();
void downloadLink();
+ void downloadTwoLinks();
};
enum DownloadTestUserAction {
@@ -414,5 +415,96 @@ void tst_QWebEngineDownloads::downloadLink()
QCOMPARE(file.readAll(), fileContents);
}
+void tst_QWebEngineDownloads::downloadTwoLinks()
+{
+ HttpServer server;
+ QWebEngineProfile profile;
+ QWebEnginePage page(&profile);
+ QWebEngineView view;
+ view.setPage(&page);
+
+ view.load(server.url());
+ view.show();
+ auto indexRR = waitForRequest(&server);
+ QVERIFY(indexRR);
+ QCOMPARE(indexRR->requestMethod(), QByteArrayLiteral("GET"));
+ QCOMPARE(indexRR->requestPath(), QByteArrayLiteral("/"));
+ indexRR->setResponseHeader(QByteArrayLiteral("content-type"), QByteArrayLiteral("text/html"));
+ indexRR->setResponseBody(QByteArrayLiteral("<html><body><a href=\"file1\" download>Link1</a><br/><a href=\"file2\">Link2</a></body></html>"));
+ indexRR->sendResponse();
+ bool loadOk = false;
+ QVERIFY(waitForSignal(&page, &QWebEnginePage::loadFinished, [&](bool ok){ loadOk = ok; }));
+ QVERIFY(loadOk);
+
+ auto favIconRR = waitForRequest(&server);
+ QVERIFY(favIconRR);
+ QCOMPARE(favIconRR->requestMethod(), QByteArrayLiteral("GET"));
+ QCOMPARE(favIconRR->requestPath(), QByteArrayLiteral("/favicon.ico"));
+ favIconRR->setResponseStatus(404);
+ favIconRR->sendResponse();
+
+ QWidget *renderWidget = view.focusWidget();
+ QTest::mouseClick(renderWidget, Qt::LeftButton, {}, QPoint(10, 10));
+ QTest::mouseClick(renderWidget, Qt::LeftButton, {}, QPoint(10, 30));
+
+ auto file1RR = waitForRequest(&server);
+ QVERIFY(file1RR);
+ QCOMPARE(file1RR->requestMethod(), QByteArrayLiteral("GET"));
+ QCOMPARE(file1RR->requestPath(), QByteArrayLiteral("/file1"));
+ auto file2RR = waitForRequest(&server);
+ QVERIFY(file2RR);
+ QCOMPARE(file2RR->requestMethod(), QByteArrayLiteral("GET"));
+ QCOMPARE(file2RR->requestPath(), QByteArrayLiteral("/file2"));
+
+ file1RR->setResponseHeader(QByteArrayLiteral("content-type"), QByteArrayLiteral("text/plain"));
+ file1RR->setResponseBody(QByteArrayLiteral("file1"));
+ file1RR->sendResponse();
+ file2RR->setResponseHeader(QByteArrayLiteral("content-type"), QByteArrayLiteral("text/plain"));
+ file2RR->setResponseHeader(QByteArrayLiteral("content-disposition"), QByteArrayLiteral("attachment"));
+ file2RR->setResponseBody(QByteArrayLiteral("file2"));
+ file2RR->sendResponse();
+
+ QTemporaryDir tmpDir;
+ QVERIFY(tmpDir.isValid());
+ QString standardDir = QStandardPaths::writableLocation(QStandardPaths::DownloadLocation);
+ QWebEngineDownloadItem *item1 = nullptr;
+ QVERIFY(waitForSignal(&profile, &QWebEngineProfile::downloadRequested,
+ [&](QWebEngineDownloadItem *item) {
+ QCOMPARE(item->state(), QWebEngineDownloadItem::DownloadRequested);
+ QCOMPARE(item->isFinished(), false);
+ 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);
+ QCOMPARE(item->url(), server.url(QByteArrayLiteral("/file1")));
+ item->setPath(tmpDir.path() + QByteArrayLiteral("/file1"));
+ item->accept();
+ item1 = item;
+ }));
+ QVERIFY(item1);
+
+ QWebEngineDownloadItem *item2 = nullptr;
+ QVERIFY(waitForSignal(&profile, &QWebEngineProfile::downloadRequested,
+ [&](QWebEngineDownloadItem *item) {
+ QCOMPARE(item->state(), QWebEngineDownloadItem::DownloadRequested);
+ QCOMPARE(item->isFinished(), false);
+ 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("/file2"));
+ QCOMPARE(item->savePageFormat(), QWebEngineDownloadItem::UnknownSaveFormat);
+ QCOMPARE(item->url(), server.url(QByteArrayLiteral("/file2")));
+ item->setPath(tmpDir.path() + QByteArrayLiteral("/file2"));
+ item->accept();
+ item2 = item;
+ }));
+ QVERIFY(item2);
+}
+
QTEST_MAIN(tst_QWebEngineDownloads)
#include "tst_qwebenginedownloads.moc"