summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2018-02-08 11:21:16 +0100
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2018-02-16 11:52:23 +0000
commit51658fac63299f818afd8ddde6dccee66a36efda (patch)
tree6ba12a277b81014340101899c542b153d37b9201 /tests
parent68a140dd4bbb9f2dd40fadb0d5110ba8f11db24e (diff)
Stabilize tst_QWebEngineDownloads::downloadTwoLinks
Change-Id: I217fd42c7fa822998ed2e1ebfe952a1f2d505ffc Reviewed-by: Michal Klocek <michal.klocek@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/widgets/qwebenginedownloads/BLACKLIST4
-rw-r--r--tests/auto/widgets/qwebenginedownloads/tst_qwebenginedownloads.cpp74
2 files changed, 38 insertions, 40 deletions
diff --git a/tests/auto/widgets/qwebenginedownloads/BLACKLIST b/tests/auto/widgets/qwebenginedownloads/BLACKLIST
deleted file mode 100644
index f8a97e9e8..000000000
--- a/tests/auto/widgets/qwebenginedownloads/BLACKLIST
+++ /dev/null
@@ -1,4 +0,0 @@
-[downloadLink]
-*
-[downloadTwoLinks]
-*
diff --git a/tests/auto/widgets/qwebenginedownloads/tst_qwebenginedownloads.cpp b/tests/auto/widgets/qwebenginedownloads/tst_qwebenginedownloads.cpp
index 1d40d91ee..ee11bab9d 100644
--- a/tests/auto/widgets/qwebenginedownloads/tst_qwebenginedownloads.cpp
+++ b/tests/auto/widgets/qwebenginedownloads/tst_qwebenginedownloads.cpp
@@ -287,6 +287,7 @@ void tst_QWebEngineDownloads::downloadLink()
HttpServer server;
QWebEngineProfile profile;
+ profile.setHttpCacheType(QWebEngineProfile::NoCache);
QWebEnginePage page(&profile);
QWebEngineView view;
view.setPage(&page);
@@ -425,7 +426,26 @@ void tst_QWebEngineDownloads::downloadTwoLinks()
results.append(rr);
});
+ QTemporaryDir tmpDir;
+ QVERIFY(tmpDir.isValid());
+ QString standardDir = QStandardPaths::writableLocation(QStandardPaths::DownloadLocation);
+
QWebEngineProfile profile;
+ profile.setHttpCacheType(QWebEngineProfile::NoCache);
+ QList<QPointer<QWebEngineDownloadItem>> downloadItems;
+ connect(&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);
+ QString filePart = QChar('/') + item->url().fileName();
+ QCOMPARE(item->path(), standardDir + filePart);
+ item->setPath(tmpDir.path() + filePart);
+ item->accept();
+ downloadItems.append(item);
+ });
+
QWebEnginePage page(&profile);
QWebEngineView view;
view.setPage(&page);
@@ -479,44 +499,26 @@ void tst_QWebEngineDownloads::downloadTwoLinks()
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->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;
- }));
+ // Now wait for downloadRequested signals:
+ QTRY_VERIFY(downloadItems.count() >= 2);
+ QScopedPointer<QWebEngineDownloadItem> item1(downloadItems.takeFirst());
+ QScopedPointer<QWebEngineDownloadItem> item2(downloadItems.takeFirst());
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->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);
+
+ // Handle one request overtaking the other
+ if (item1->url().fileName() == QByteArrayLiteral("file2"))
+ qSwap(item1, item2);
+
+ QTRY_COMPARE(item1->state(), QWebEngineDownloadItem::DownloadCompleted);
+ QCOMPARE(item1->mimeType(), QStringLiteral("text/plain"));
+ QCOMPARE(item1->savePageFormat(), QWebEngineDownloadItem::UnknownSaveFormat);
+ QCOMPARE(item1->url(), server.url(QByteArrayLiteral("/file1")));
+
+ QTRY_COMPARE(item2->state(), QWebEngineDownloadItem::DownloadCompleted);
+ QCOMPARE(item2->mimeType(), QStringLiteral("text/plain"));
+ QCOMPARE(item2->savePageFormat(), QWebEngineDownloadItem::UnknownSaveFormat);
+ QCOMPARE(item2->url(), server.url(QByteArrayLiteral("/file2")));
}
void tst_QWebEngineDownloads::downloadPage_data()