summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorMichael BrĂ¼ning <michael.bruning@qt.io>2020-07-24 10:30:54 +0200
committerMichael BrĂ¼ning <michael.bruning@qt.io>2020-07-24 15:23:10 +0200
commit54b84e14589b3e51f2f2e7980e2af2559601efe2 (patch)
treeeafef9f5b854cd90f6fa8e1ae5ab9e161a424aa3 /tests/auto
parent27332664b2745d7d322b8afbc1a41dc0fbfc763a (diff)
parenta2a19a6965601ced75e3e48b2bf618ba2bdbd29e (diff)
Merge remote-tracking branch 'origin/5.15' into dev
Conflicts: src/core/compositor/delegated_frame_node.cpp src/core/core_chromium.pri src/core/render_widget_host_view_qt.cpp Change-Id: I9387151e9647c87fc387095e7b6d8d66560cdf71
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/core/qwebenginecookiestore/qwebenginecookiestore.pro1
-rw-r--r--tests/auto/core/qwebenginecookiestore/tst_qwebenginecookiestore.cpp72
-rw-r--r--tests/auto/shared/httpreqrep.cpp2
-rw-r--r--tests/auto/widgets/proxypac/tst_proxypac.cpp2
-rw-r--r--tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp29
-rw-r--r--tests/auto/widgets/qwebengineprofile/tst_qwebengineprofile.cpp5
6 files changed, 107 insertions, 4 deletions
diff --git a/tests/auto/core/qwebenginecookiestore/qwebenginecookiestore.pro b/tests/auto/core/qwebenginecookiestore/qwebenginecookiestore.pro
index e99c7f493..9c239f1a7 100644
--- a/tests/auto/core/qwebenginecookiestore/qwebenginecookiestore.pro
+++ b/tests/auto/core/qwebenginecookiestore/qwebenginecookiestore.pro
@@ -1 +1,2 @@
include(../tests.pri)
+include(../../shared/http.pri)
diff --git a/tests/auto/core/qwebenginecookiestore/tst_qwebenginecookiestore.cpp b/tests/auto/core/qwebenginecookiestore/tst_qwebenginecookiestore.cpp
index 2c41aa9b1..638b2e028 100644
--- a/tests/auto/core/qwebenginecookiestore/tst_qwebenginecookiestore.cpp
+++ b/tests/auto/core/qwebenginecookiestore/tst_qwebenginecookiestore.cpp
@@ -33,6 +33,9 @@
#include <QtWebEngineWidgets/qwebenginepage.h>
#include <QtWebEngineWidgets/qwebengineprofile.h>
+#include "httpserver.h"
+#include "httpreqrep.h"
+
class tst_QWebEngineCookieStore : public QObject
{
Q_OBJECT
@@ -56,6 +59,7 @@ private Q_SLOTS:
void cookieSignals();
void batchCookieTasks();
void basicFilter();
+ void basicFilterOverHTTP();
void html5featureFilter();
private:
@@ -239,6 +243,74 @@ void tst_QWebEngineCookieStore::basicFilter()
QCOMPARE(cookieAddedSpy.count(), 2);
}
+void tst_QWebEngineCookieStore::basicFilterOverHTTP()
+{
+ QWebEnginePage page(m_profile);
+ QWebEngineCookieStore *client = m_profile->cookieStore();
+
+ QAtomicInt accessTested = 0;
+ client->setCookieFilter([&](const QWebEngineCookieStore::FilterRequest &) { ++accessTested; return true; });
+
+ HttpServer httpServer;
+
+ if (!httpServer.start())
+ QSKIP("Failed to start http server");
+
+ QByteArray cookieRequestHeader;
+ connect(&httpServer, &HttpServer::newRequest, [&cookieRequestHeader](HttpReqRep *rr) {
+ if (rr->requestPath().size() <= 1) {
+ cookieRequestHeader = rr->requestHeader(QByteArrayLiteral("Cookie"));
+ rr->setResponseStatus(200);
+ if (cookieRequestHeader.isEmpty())
+ rr->setResponseHeader(QByteArrayLiteral("Set-Cookie"), QByteArrayLiteral("Test=test"));
+ rr->sendResponse();
+ } else {
+ rr->setResponseStatus(404);
+ rr->sendResponse();
+ }
+ });
+
+ QSignalSpy loadSpy(&page, SIGNAL(loadFinished(bool)));
+ QSignalSpy cookieAddedSpy(client, SIGNAL(cookieAdded(const QNetworkCookie &)));
+ QSignalSpy cookieRemovedSpy(client, SIGNAL(cookieRemoved(const QNetworkCookie &)));
+
+ page.load(httpServer.url());
+
+ QTRY_COMPARE_WITH_TIMEOUT(loadSpy.count(), 1, 30000);
+ QVERIFY(loadSpy.takeFirst().takeFirst().toBool());
+ QTRY_COMPARE(cookieAddedSpy.count(), 1);
+ QTRY_COMPARE(accessTested.loadAcquire(), 3);
+ QVERIFY(cookieRequestHeader.isEmpty());
+
+ page.triggerAction(QWebEnginePage::Reload);
+ QTRY_COMPARE(loadSpy.count(), 1);
+ QVERIFY(loadSpy.takeFirst().takeFirst().toBool());
+ QVERIFY(!cookieRequestHeader.isEmpty());
+ QTRY_COMPARE(cookieAddedSpy.count(), 1);
+ QTRY_COMPARE(accessTested.loadAcquire(), 5);
+
+ client->deleteAllCookies();
+ QTRY_COMPARE(cookieRemovedSpy.count(), 1);
+
+ client->setCookieFilter([&](const QWebEngineCookieStore::FilterRequest &) { ++accessTested; return false; });
+ page.triggerAction(QWebEnginePage::ReloadAndBypassCache);
+ QTRY_COMPARE(loadSpy.count(), 1);
+ QVERIFY(loadSpy.takeFirst().takeFirst().toBool());
+ QVERIFY(cookieRequestHeader.isEmpty());
+ // Test cookies are NOT added:
+ QTest::qWait(100);
+ QCOMPARE(cookieAddedSpy.count(), 1);
+ QTRY_COMPARE(accessTested.loadAcquire(), 8);
+
+ page.triggerAction(QWebEnginePage::Reload);
+ QTRY_COMPARE(loadSpy.count(), 1);
+ QVERIFY(loadSpy.takeFirst().takeFirst().toBool());
+ QVERIFY(cookieRequestHeader.isEmpty());
+ QCOMPARE(cookieAddedSpy.count(), 1);
+
+ (void) httpServer.stop();
+}
+
void tst_QWebEngineCookieStore::html5featureFilter()
{
QWebEnginePage page(m_profile);
diff --git a/tests/auto/shared/httpreqrep.cpp b/tests/auto/shared/httpreqrep.cpp
index 15a86631c..b1b6a0a04 100644
--- a/tests/auto/shared/httpreqrep.cpp
+++ b/tests/auto/shared/httpreqrep.cpp
@@ -67,7 +67,7 @@ void HttpReqRep::close()
QByteArray HttpReqRep::requestHeader(const QByteArray &key) const
{
- auto it = m_requestHeaders.find(key);
+ auto it = m_requestHeaders.find(key.toLower());
if (it != m_requestHeaders.end())
return it->second;
return {};
diff --git a/tests/auto/widgets/proxypac/tst_proxypac.cpp b/tests/auto/widgets/proxypac/tst_proxypac.cpp
index 934e23fde..dabbfb4e5 100644
--- a/tests/auto/widgets/proxypac/tst_proxypac.cpp
+++ b/tests/auto/widgets/proxypac/tst_proxypac.cpp
@@ -46,7 +46,7 @@ private slots:
void tst_ProxyPac::proxypac()
{
- const QString fromEnv = QString::fromLocal8Bit(qgetenv("QTWEBENGINE_CHROMIUM_FLAGS"));
+ const QString fromEnv = qEnvironmentVariable("QTWEBENGINE_CHROMIUM_FLAGS");
if (!fromEnv.contains("--proxy-pac-url"))
qFatal("--proxy-pac-url argument is not passed.");
diff --git a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp
index 9768747ca..550548418 100644
--- a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp
+++ b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp
@@ -92,6 +92,7 @@ private Q_SLOTS:
void comboBoxPopupPositionAfterChildMove();
void acceptNavigationRequest();
void acceptNavigationRequestNavigationType();
+ void acceptNavigationRequestRelativeToNothing();
void geolocationRequestJS_data();
void geolocationRequestJS();
void loadFinished();
@@ -601,6 +602,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;
diff --git a/tests/auto/widgets/qwebengineprofile/tst_qwebengineprofile.cpp b/tests/auto/widgets/qwebengineprofile/tst_qwebengineprofile.cpp
index 908b38202..fad94259c 100644
--- a/tests/auto/widgets/qwebengineprofile/tst_qwebengineprofile.cpp
+++ b/tests/auto/widgets/qwebengineprofile/tst_qwebengineprofile.cpp
@@ -136,12 +136,13 @@ void tst_QWebEngineProfile::privateProfile()
QCOMPARE(otrProfile.httpCacheType(), QWebEngineProfile::MemoryHttpCache);
QCOMPARE(otrProfile.persistentCookiesPolicy(), QWebEngineProfile::NoPersistentCookies);
QCOMPARE(otrProfile.cachePath(), QString());
- QCOMPARE(otrProfile.persistentStoragePath(), QString());
+ QCOMPARE(otrProfile.persistentStoragePath(), QStandardPaths::writableLocation(QStandardPaths::DataLocation)
+ + QStringLiteral("/QtWebEngine/OffTheRecord"));
// TBD: setters do not really work
otrProfile.setCachePath(QStringLiteral("/home/foo/bar"));
QCOMPARE(otrProfile.cachePath(), QString());
otrProfile.setPersistentStoragePath(QStringLiteral("/home/foo/bar"));
- QCOMPARE(otrProfile.persistentStoragePath(), QString());
+ QCOMPARE(otrProfile.persistentStoragePath(), QStringLiteral("/home/foo/bar"));
otrProfile.setHttpCacheType(QWebEngineProfile::DiskHttpCache);
QCOMPARE(otrProfile.httpCacheType(), QWebEngineProfile::MemoryHttpCache);
otrProfile.setPersistentCookiesPolicy(QWebEngineProfile::ForcePersistentCookies);