diff options
author | Jüri Valdmann <juri.valdmann@qt.io> | 2020-07-22 11:18:26 +0200 |
---|---|---|
committer | Jüri Valdmann <juri.valdmann@qt.io> | 2020-07-22 12:21:48 +0200 |
commit | 293397cc577eb8e0805e0ef68f960dbb4574cf24 (patch) | |
tree | 93bfc3bc5f5cdca33296ffbc3108bcae5dab69a5 /tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp | |
parent | 69be445c4412c886c6c9619fe377265a958844b8 (diff) |
Fix incorrect doc for acceptNavigationRequest and add test
The function is called for all navigation requests. The original bug
report was most likely due to the use relative links on a page without
a base url, which indeed results in no call to acceptNavigationRequest
being made. But this has nothing to do with local vs remote URLs, it's
rather that relative links, which are relative to nothing, are not
valid links and there thus cannot be any navigation request either.
Task-number: QTBUG-48435
Change-Id: I08bd0c86d67bf1dd1d7662468321777254a7db0b
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp')
-rw-r--r-- | tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp index 621c2dbd7..a3c45918b 100644 --- a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp +++ b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp @@ -93,6 +93,7 @@ private Q_SLOTS: void comboBoxPopupPositionAfterChildMove(); void acceptNavigationRequest(); void acceptNavigationRequestNavigationType(); + void acceptNavigationRequestRelativeToNothing(); void geolocationRequestJS_data(); void geolocationRequestJS(); void loadFinished(); @@ -602,6 +603,34 @@ void tst_QWebEnginePage::acceptNavigationRequestNavigationType() } } +// Relative url without base url. +// +// See also: QTBUG-48435 +void tst_QWebEnginePage::acceptNavigationRequestRelativeToNothing() +{ + TestPage page; + QSignalSpy loadSpy(&page, SIGNAL(loadFinished(bool))); + + page.setHtml(QString("<html><body><a id='link' href='S0'>limited time offer</a></body></html>"), + /* baseUrl: */ QUrl()); + QTRY_COMPARE_WITH_TIMEOUT(loadSpy.count(), 1, 20000); + page.runJavaScript(QStringLiteral("document.getElementById(\"link\").click()")); + QTRY_COMPARE_WITH_TIMEOUT(loadSpy.count(), 2, 20000); + page.setHtml(QString("<html><body><a id='link' href='S0'>limited time offer</a></body></html>"), + /* baseUrl: */ QString("qrc:/")); + QTRY_COMPARE_WITH_TIMEOUT(loadSpy.count(), 3, 20000); + page.runJavaScript(QStringLiteral("document.getElementById(\"link\").click()")); + QTRY_COMPARE_WITH_TIMEOUT(loadSpy.count(), 4, 20000); + + // The two setHtml and the second click are counted, while the + // first click is ignored due to the empty base url. + QCOMPARE(page.navigations.count(), 3); + QCOMPARE(page.navigations[0].type, QWebEnginePage::NavigationTypeTyped); + QCOMPARE(page.navigations[1].type, QWebEnginePage::NavigationTypeTyped); + QCOMPARE(page.navigations[2].type, QWebEnginePage::NavigationTypeLinkClicked); + QCOMPARE(page.navigations[2].url, QUrl(QString("qrc:/S0"))); +} + void tst_QWebEnginePage::popupFormSubmission() { TestPage page; |