summaryrefslogtreecommitdiffstats
path: root/tests/auto/widgets/proxy/tst_proxy.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/widgets/proxy/tst_proxy.cpp')
-rw-r--r--tests/auto/widgets/proxy/tst_proxy.cpp35
1 files changed, 34 insertions, 1 deletions
diff --git a/tests/auto/widgets/proxy/tst_proxy.cpp b/tests/auto/widgets/proxy/tst_proxy.cpp
index 5f5dec016..c3e3c88a4 100644
--- a/tests/auto/widgets/proxy/tst_proxy.cpp
+++ b/tests/auto/widgets/proxy/tst_proxy.cpp
@@ -32,6 +32,17 @@
#include <QNetworkProxy>
#include <QWebEnginePage>
#include <QWebEngineView>
+#include <QWebEngineUrlRequestInterceptor>
+
+
+struct Interceptor : public QWebEngineUrlRequestInterceptor
+{
+ Interceptor(const QByteArray cookie):m_cookie(cookie){};
+ void interceptRequest(QWebEngineUrlRequestInfo &info) override {
+ info.setHttpHeader(QByteArray("Cookie"), m_cookie);
+ };
+ QByteArray m_cookie;
+};
class tst_Proxy : public QObject {
@@ -41,8 +52,10 @@ public:
private slots:
void proxyAuthentication();
+ void forwardCookie();
};
+
void tst_Proxy::proxyAuthentication()
{
QByteArray user(QByteArrayLiteral("test"));
@@ -59,11 +72,31 @@ void tst_Proxy::proxyAuthentication()
server.run();
QTRY_VERIFY2(server.isListening(), "Could not setup authentication server");
QWebEnginePage page;
- QSignalSpy successSpy(&server, &ProxyServer::success);
+ QSignalSpy successSpy(&server, &ProxyServer::authenticationSuccess);
page.load(QUrl("http://www.qt.io"));
QTRY_VERIFY2(successSpy.count() > 0, "Could not get authentication token");
}
+void tst_Proxy::forwardCookie()
+{
+ QNetworkProxy proxy;
+ proxy.setType(QNetworkProxy::HttpProxy);
+ proxy.setHostName("localhost");
+ proxy.setPort(5555);
+ QNetworkProxy::setApplicationProxy(proxy);
+ ProxyServer server;
+ QByteArray cookie("foo=bar; sessionToken=123");
+ server.setCookie(cookie);
+ server.run();
+ QTRY_VERIFY2(server.isListening(), "Could not setup proxy server");
+ Interceptor interceptor(cookie);
+ QWebEnginePage page;
+ page.setUrlRequestInterceptor(&interceptor);
+ QSignalSpy cookieSpy(&server, &ProxyServer::cookieMatch);
+ page.load(QUrl("http://www.qt.io"));
+ QTRY_VERIFY2(cookieSpy.count() > 0, "Could not get cookie");
+}
+
#include "tst_proxy.moc"
QTEST_MAIN(tst_Proxy)