From 3da642b723667e8ba349291c2a98feca121244bb Mon Sep 17 00:00:00 2001 From: Luca Niccoli Date: Mon, 4 May 2015 14:13:14 +0200 Subject: Send and parse headers for the handshake request Task-number: QTBUG-40842 Change-Id: I02787a0e55701966e564a312d51297f4160bd89a Reviewed-by: Liang Qi --- tests/auto/qwebsocket/tst_qwebsocket.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'tests/auto') diff --git a/tests/auto/qwebsocket/tst_qwebsocket.cpp b/tests/auto/qwebsocket/tst_qwebsocket.cpp index 2422012..4a0e06b 100644 --- a/tests/auto/qwebsocket/tst_qwebsocket.cpp +++ b/tests/auto/qwebsocket/tst_qwebsocket.cpp @@ -52,6 +52,7 @@ public: Q_SIGNALS: void newConnection(QUrl requestUrl); + void newConnection(QNetworkRequest request); private Q_SLOTS: void onNewConnection(); @@ -87,6 +88,7 @@ void EchoServer::onNewConnection() QWebSocket *pSocket = m_pWebSocketServer->nextPendingConnection(); Q_EMIT newConnection(pSocket->requestUrl()); + Q_EMIT newConnection(pSocket->request()); connect(pSocket, SIGNAL(textMessageReceived(QString)), this, SLOT(processTextMessage(QString))); connect(pSocket, SIGNAL(binaryMessageReceived(QByteArray)), this, SLOT(processBinaryMessage(QByteArray))); @@ -589,17 +591,23 @@ void tst_QWebSocket::tst_openRequest() QWebSocket socket; QSignalSpy socketConnectedSpy(&socket, SIGNAL(connected())); + QSignalSpy serverRequestSpy(&echoServer, SIGNAL(newConnection(QNetworkRequest))); QUrl url = QUrl(QStringLiteral("ws://") + echoServer.hostAddress().toString() + QLatin1Char(':') + QString::number(echoServer.port())); url.addQueryItem("queryitem", "with encoded characters"); QNetworkRequest req(url); + req.setRawHeader("X-Custom-Header", "A custom header"); socket.open(req); if (socketConnectedSpy.count() == 0) QVERIFY(socketConnectedSpy.wait(500)); QCOMPARE(socket.state(), QAbstractSocket::ConnectedState); - + QCOMPARE(serverRequestSpy.count(), 1); + QList arguments = serverRequestSpy.takeFirst(); + QNetworkRequest requestConnected = arguments.at(0).value(); + QCOMPARE(requestConnected.url(), req.url()); + QCOMPARE(requestConnected.rawHeader("X-Custom-Header"), req.rawHeader("X-Custom-Header")); socket.close(); } -- cgit v1.2.1