diff options
author | Tamas Zakor <ztamas@inf.u-szeged.hu> | 2020-05-27 10:12:08 +0200 |
---|---|---|
committer | Tamas Zakor <ztamas@inf.u-szeged.hu> | 2020-06-10 15:31:12 +0200 |
commit | 93f435e5ed5f232825bfa1d299ad4069eaed720f (patch) | |
tree | e14d898d74ebd52b23179d24da54d51dc7736dee | |
parent | 8e793d7ea7de7c1db40ef18cd8e2844ea1e6a7d4 (diff) |
Add auto test for safe redirect
Task-number: QTBUG-84011
Change-Id: Ie1eef3bc850e99437bb02bea01e06a49029e0dc4
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
-rw-r--r-- | tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp index 0368e7af5..621c2dbd7 100644 --- a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp +++ b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp @@ -230,6 +230,8 @@ private Q_SLOTS: void backgroundColor(); void audioMuted(); void closeContents(); + void isSafeRedirect_data(); + void isSafeRedirect(); private: static QPoint elementCenter(QWebEnginePage *page, const QString &id); @@ -4649,6 +4651,36 @@ void tst_QWebEnginePage::closeContents() delete dialogView; } +// Based on QTBUG-84011 +void tst_QWebEnginePage::isSafeRedirect_data() +{ + QTest::addColumn<QUrl>("requestedUrl"); + QTest::addColumn<QUrl>("expectedUrl"); + QString fileScheme = "file://"; + +#ifdef Q_OS_WIN + fileScheme += "/"; +#endif + + QString tempDir(fileScheme + QDir::tempPath()); + QTest::newRow(qPrintable(tempDir)) << QUrl(tempDir) << QUrl(tempDir + "/"); + QTest::newRow(qPrintable(tempDir + QString("/foo/bar"))) << QUrl(tempDir + "/foo/bar") << QUrl(tempDir + "/foo/bar"); + QTest::newRow("filesystem:http://foo.com/bar") << QUrl("filesystem:http://foo.com/bar") << QUrl("filesystem:http://foo.com/bar/"); +} + +void tst_QWebEnginePage::isSafeRedirect() +{ + QFETCH(QUrl, requestedUrl); + QFETCH(QUrl, expectedUrl); + + TestPage page; + QSignalSpy spy(&page, SIGNAL(loadFinished(bool))); + page.setUrl(requestedUrl); + QTRY_COMPARE_WITH_TIMEOUT(spy.count(), 1, 20000); + QCOMPARE(page.url(), expectedUrl); + spy.clear(); +} + static QByteArrayList params = {QByteArrayLiteral("--use-fake-device-for-media-stream")}; W_QTEST_MAIN(tst_QWebEnginePage, params) |