From 3d0de6eff785f657346435efdefbcde55a03a3f4 Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Tue, 9 Jan 2018 17:33:39 +0100 Subject: Stabilize tst_QWebEngineDownloads::downloadTwoLinks() It was vulnerable to race conditions if two requests were send before the first was caught. Change-Id: Ia0b68594337028675678ad190f261202372c2ad6 Reviewed-by: Viktor Engelmann --- .../qwebenginedownloads/tst_qwebenginedownloads.cpp | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/widgets/qwebenginedownloads/tst_qwebenginedownloads.cpp b/tests/auto/widgets/qwebenginedownloads/tst_qwebenginedownloads.cpp index 6ba6d78a4..c25e82d41 100644 --- a/tests/auto/widgets/qwebenginedownloads/tst_qwebenginedownloads.cpp +++ b/tests/auto/widgets/qwebenginedownloads/tst_qwebenginedownloads.cpp @@ -27,6 +27,7 @@ ****************************************************************************/ #include +#include #include #include #include @@ -420,6 +421,13 @@ void tst_QWebEngineDownloads::downloadLink() void tst_QWebEngineDownloads::downloadTwoLinks() { HttpServer server; + QSignalSpy requestSpy(&server, &HttpServer::newRequest); + QList results; + connect(&server, &HttpServer::newRequest, [&](HttpReqRep *rr) { + rr->setParent(nullptr); + results.append(rr); + }); + QWebEngineProfile profile; QWebEnginePage page(&profile); QWebEngineView view; @@ -427,7 +435,8 @@ void tst_QWebEngineDownloads::downloadTwoLinks() view.load(server.url()); view.show(); - auto indexRR = waitForRequest(&server); + QTRY_COMPARE(requestSpy.count(), 1); + std::unique_ptr indexRR(results.takeFirst()); QVERIFY(indexRR); QCOMPARE(indexRR->requestMethod(), QByteArrayLiteral("GET")); QCOMPARE(indexRR->requestPath(), QByteArrayLiteral("/")); @@ -438,7 +447,8 @@ void tst_QWebEngineDownloads::downloadTwoLinks() QVERIFY(waitForSignal(&page, &QWebEnginePage::loadFinished, [&](bool ok){ loadOk = ok; })); QVERIFY(loadOk); - auto favIconRR = waitForRequest(&server); + QTRY_COMPARE(requestSpy.count(), 2); + std::unique_ptr favIconRR(results.takeFirst()); QVERIFY(favIconRR); QCOMPARE(favIconRR->requestMethod(), QByteArrayLiteral("GET")); QCOMPARE(favIconRR->requestPath(), QByteArrayLiteral("/favicon.ico")); @@ -449,11 +459,13 @@ void tst_QWebEngineDownloads::downloadTwoLinks() QTest::mouseClick(renderWidget, Qt::LeftButton, {}, QPoint(10, 10)); QTest::mouseClick(renderWidget, Qt::LeftButton, {}, QPoint(10, 30)); - auto file1RR = waitForRequest(&server); + QTRY_VERIFY(requestSpy.count() >= 3); + std::unique_ptr file1RR(results.takeFirst()); QVERIFY(file1RR); QCOMPARE(file1RR->requestMethod(), QByteArrayLiteral("GET")); QCOMPARE(file1RR->requestPath(), QByteArrayLiteral("/file1")); - auto file2RR = waitForRequest(&server); + QTRY_COMPARE(requestSpy.count(), 4); + std::unique_ptr file2RR(results.takeFirst()); QVERIFY(file2RR); QCOMPARE(file2RR->requestMethod(), QByteArrayLiteral("GET")); QCOMPARE(file2RR->requestPath(), QByteArrayLiteral("/file2")); -- cgit v1.2.3 From ed3a0f052910b09edc393dfb6c6940f118b267ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCri=20Valdmann?= Date: Fri, 15 Dec 2017 15:19:28 +0100 Subject: ProxyConfigServiceQt: Use default HostPortPair for SCHEME_DIRECT Unlike QNetworkProxy, Chromium's net::ProxyServer expects the hostname and port to be at default values for special schemes (DIRECT and INVALID). Otherwise, a DCHECK is triggered at proxy_server.cc:73. Change-Id: I1ac6c425ea03fcbfe084d25c2fd05bf174c753d6 Reviewed-by: Viktor Engelmann --- .../widgets/qwebenginepage/tst_qwebenginepage.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'tests/auto') diff --git a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp index e3d6a7435..182094a11 100644 --- a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp +++ b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -210,6 +211,7 @@ private Q_SLOTS: void viewSource(); void viewSourceURL_data(); void viewSourceURL(); + void proxyConfigWithUnexpectedHostPortPair(); private: static QPoint elementCenter(QWebEnginePage *page, const QString &id); @@ -4353,5 +4355,22 @@ void tst_QWebEnginePage::viewSourceURL() QVERIFY(!page.action(QWebEnginePage::ViewSource)->isEnabled()); } +Q_DECLARE_METATYPE(QNetworkProxy::ProxyType); + +void tst_QWebEnginePage::proxyConfigWithUnexpectedHostPortPair() +{ + // Chromium expects a proxy of type NoProxy to not have a host or port set. + + QNetworkProxy proxy; + proxy.setType(QNetworkProxy::NoProxy); + proxy.setHostName(QStringLiteral("127.0.0.1")); + proxy.setPort(244); + QNetworkProxy::setApplicationProxy(proxy); + + QSignalSpy loadFinishedSpy(m_page, SIGNAL(loadFinished(bool))); + m_page->load(QStringLiteral("http://127.0.0.1:245/")); + QTRY_COMPARE(loadFinishedSpy.count(), 1); +} + QTEST_MAIN(tst_QWebEnginePage) #include "tst_qwebenginepage.moc" -- cgit v1.2.3