From a1a2bd2d30f756c5fb51ae2c9e2575e56be05c97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCri=20Valdmann?= Date: Mon, 16 Oct 2017 12:49:26 +0200 Subject: Add tests setUrlToBadDomain and setUrlToBadPort Document the somewhat strange behavior of the signals QWebEnginePage::urlChanged, QWebEnginePage::titleChanged, and QWebEnginePage::loadFinished when trying to load invalid URLs via QWebEnginePage::setUrl. Change-Id: I5218a49105ad6187f87e7091589b5175f4349593 Reviewed-by: Peter Varga Reviewed-by: Allan Sandfeld Jensen --- .../widgets/qwebenginepage/tst_qwebenginepage.cpp | 88 ++++++++++++++++++++++ 1 file changed, 88 insertions(+) (limited to 'tests') diff --git a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp index 76a0bbf4d..35e703bbc 100644 --- a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp +++ b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp @@ -193,6 +193,8 @@ private Q_SLOTS: void setUrlWithPendingLoads(); void setUrlToEmpty(); void setUrlToInvalid(); + void setUrlToBadDomain(); + void setUrlToBadPort(); void setUrlHistory(); void setUrlUsingStateObject(); void setUrlThenLoads_data(); @@ -3829,6 +3831,92 @@ void tst_QWebEnginePage::setUrlToInvalid() QCOMPARE(baseUrlSync(&page), aboutBlank); } +void tst_QWebEnginePage::setUrlToBadDomain() +{ + // Failing to load a URL should still emit a urlChanged signal. + // + // This test is based on the scenario in QTBUG-48995 where the second setUrl + // call first triggers an unexpected additional urlChanged signal with the + // original url before the expected signal with the new url. + + // RFC 2606 says the .invalid TLD should be invalid. + const QUrl url1 = QStringLiteral("http://this.is.definitely.invalid/"); + const QUrl url2 = QStringLiteral("http://this.is.also.invalid/"); + QWebEnginePage page; + QSignalSpy urlSpy(&page, &QWebEnginePage::urlChanged); + QSignalSpy titleSpy(&page, &QWebEnginePage::titleChanged); + QSignalSpy loadSpy(&page, &QWebEnginePage::loadFinished); + + page.setUrl(url1); + + QTRY_COMPARE(urlSpy.count(), 1); + QTRY_COMPARE(titleSpy.count(), 2); + QTRY_COMPARE(loadSpy.count(), 1); + + QCOMPARE(urlSpy.takeFirst().value(0).toUrl(), url1); + QCOMPARE(titleSpy.takeFirst().value(0).toString(), url1.host()); + QCOMPARE(titleSpy.takeFirst().value(0).toString(), url1.host()); + QCOMPARE(loadSpy.takeFirst().value(0).toBool(), false); + + QCOMPARE(page.url(), url1); + QCOMPARE(page.title(), url1.host()); + + page.setUrl(url2); + + QTRY_COMPARE(urlSpy.count(), 1); + QTRY_COMPARE(titleSpy.count(), 2); + QTRY_COMPARE(loadSpy.count(), 1); + + QCOMPARE(urlSpy.takeFirst().value(0).toUrl(), url2); + QCOMPARE(titleSpy.takeFirst().value(0).toString(), url2.host()); + QCOMPARE(titleSpy.takeFirst().value(0).toString(), url2.host()); + QCOMPARE(loadSpy.takeFirst().value(0).toBool(), false); + + QCOMPARE(page.url(), url2); + QCOMPARE(page.title(), url2.host()); +} + +void tst_QWebEnginePage::setUrlToBadPort() +{ + // Failing to load a URL should still emit a urlChanged signal. + + // Ports 244-245 are hopefully unbound (marked unassigned in RFC1700). + const QUrl url1 = QStringLiteral("http://127.0.0.1:244/"); + const QUrl url2 = QStringLiteral("http://127.0.0.1:245/"); + QWebEnginePage page; + QSignalSpy urlSpy(&page, &QWebEnginePage::urlChanged); + QSignalSpy titleSpy(&page, &QWebEnginePage::titleChanged); + QSignalSpy loadSpy(&page, &QWebEnginePage::loadFinished); + + page.setUrl(url1); + + QTRY_COMPARE(urlSpy.count(), 1); + QTRY_COMPARE(titleSpy.count(), 2); + QTRY_COMPARE(loadSpy.count(), 1); + + QCOMPARE(urlSpy.takeFirst().value(0).toUrl(), url1); + QCOMPARE(titleSpy.takeFirst().value(0).toString(), url1.authority()); + QCOMPARE(titleSpy.takeFirst().value(0).toString(), url1.host()); + QCOMPARE(loadSpy.takeFirst().value(0).toBool(), false); + + QCOMPARE(page.url(), url1); + QCOMPARE(page.title(), url1.host()); + + page.setUrl(url2); + + QTRY_COMPARE(urlSpy.count(), 1); + QTRY_COMPARE(titleSpy.count(), 2); + QTRY_COMPARE(loadSpy.count(), 1); + + QCOMPARE(urlSpy.takeFirst().value(0).toUrl(), url2); + QCOMPARE(titleSpy.takeFirst().value(0).toString(), url2.authority()); + QCOMPARE(titleSpy.takeFirst().value(0).toString(), url2.host()); + QCOMPARE(loadSpy.takeFirst().value(0).toBool(), false); + + QCOMPARE(page.url(), url2); + QCOMPARE(page.title(), url2.host()); +} + static QStringList collectHistoryUrls(QWebEngineHistory *history) { QStringList urls; -- cgit v1.2.3