diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2021-04-14 13:35:19 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2021-04-19 13:54:51 +0000 |
commit | b29b245fcb9db741d14180ea7e8dcb3ad2d4f49a (patch) | |
tree | 15d2cc67de6d23c5592ee17e62af9c0eb0ef3698 /tests | |
parent | b5834447f319a43d1bf143c9d2d96d6fcb6dbea9 (diff) |
Report server directs in navigation type
A server redirect might not have been reflected in the navigation type
at this point, so also check the is_redirect value.
Pick-to: 5.15.4
Fixes: QTBUG-92819
Change-Id: I711ef041de69552bc3485c9cf3db68c9e6033d6a
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Reviewed-by: Kirill Burtsev <kirill.burtsev@qt.io>
Diffstat (limited to 'tests')
3 files changed, 42 insertions, 0 deletions
diff --git a/tests/auto/widgets/qwebenginepage/resources/redirect.html b/tests/auto/widgets/qwebenginepage/resources/redirect.html new file mode 100644 index 000000000..db06d73a7 --- /dev/null +++ b/tests/auto/widgets/qwebenginepage/resources/redirect.html @@ -0,0 +1,8 @@ +<html> +<body> +<script> +function doRedirect() { location.replace('qrc:///resources/content.html') } +document.addEventListener("DOMContentLoaded", doRedirect) +</script> +</body> +</html> diff --git a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp index 7e92ad8cc..e5975edcd 100644 --- a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp +++ b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp @@ -596,6 +596,39 @@ void tst_QWebEnginePage::acceptNavigationRequestNavigationType() << QWebEnginePage::NavigationTypeReload << QWebEnginePage::NavigationTypeTyped << QWebEnginePage::NavigationTypeRedirect; + + // client side redirect + page.load(QUrl("qrc:///resources/redirect.html")); + QTRY_COMPARE_WITH_TIMEOUT(loadSpy.count(), 8, 20000); + QTRY_COMPARE(page.navigations.count(), 8); + expectedList += { QWebEnginePage::NavigationTypeTyped, QWebEnginePage::NavigationTypeRedirect }; + + // server side redirect + HttpServer server; + server.setResourceDirs({ ":/resources" }); + connect(&server, &HttpServer::newRequest, &server, [&] (HttpReqRep *r) { + if (r->requestMethod() == "GET") { + if (r->requestPath() == "/redirect1.html") { + r->setResponseHeader("Location", server.url("/redirect2.html").toEncoded()); + r->setResponseBody("<html><body>Redirect1</body></html>"); + r->sendResponse(307); // Internal server redirect + } else if (r->requestPath() == "/redirect2.html") { + r->setResponseHeader("Location", server.url("/content.html").toEncoded()); + r->setResponseBody("<html><body>Redirect2</body></html>"); + r->sendResponse(301); // Moved permanently + } + } + }); + QVERIFY(server.start()); + page.load(QUrl(server.url("/redirect1.html"))); + QTRY_COMPARE_WITH_TIMEOUT(loadSpy.count(), 9, 20000); + QTRY_COMPARE(page.navigations.count(), 11); + expectedList += { + QWebEnginePage::NavigationTypeTyped, + QWebEnginePage::NavigationTypeRedirect, + QWebEnginePage::NavigationTypeRedirect + }; + QVERIFY(expectedList.count() == page.navigations.count()); for (int i = 0; i < expectedList.count(); ++i) { QCOMPARE(page.navigations[i].type, expectedList[i]); diff --git a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.qrc b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.qrc index 013a307de..3480341e8 100644 --- a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.qrc +++ b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.qrc @@ -14,6 +14,7 @@ <file>resources/user.css</file> <file>resources/image.png</file> <file>resources/pasteimage.html</file> + <file>resources/redirect.html</file> <file>resources/reload.html</file> <file>resources/style.css</file> <file>resources/test1.html</file> |