From 48418a2e16b6dede3bc002dda5a3cb277fd3e802 Mon Sep 17 00:00:00 2001 From: Luca Niccoli Date: Mon, 9 Mar 2015 18:48:31 +0100 Subject: Do not decode the HTTP resource name The resource needs to be sent encoded in the HTTP request. Task-number: QTBUG-44889 Change-Id: I3c6c56f5fea1553f3b5751de7da0cfc76150f4b9 Reviewed-by: Liang Qi --- tests/auto/qwebsocket/tst_qwebsocket.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'tests/auto') diff --git a/tests/auto/qwebsocket/tst_qwebsocket.cpp b/tests/auto/qwebsocket/tst_qwebsocket.cpp index 7659e89..aca25d0 100644 --- a/tests/auto/qwebsocket/tst_qwebsocket.cpp +++ b/tests/auto/qwebsocket/tst_qwebsocket.cpp @@ -50,6 +50,9 @@ public: QHostAddress hostAddress() const { return m_pWebSocketServer->serverAddress(); } quint16 port() const { return m_pWebSocketServer->serverPort(); } +Q_SIGNALS: + void newConnection(QUrl requestUrl); + private Q_SLOTS: void onNewConnection(); void processTextMessage(QString message); @@ -83,6 +86,8 @@ void EchoServer::onNewConnection() { QWebSocket *pSocket = m_pWebSocketServer->nextPendingConnection(); + Q_EMIT newConnection(pSocket->requestUrl()); + connect(pSocket, SIGNAL(textMessageReceived(QString)), this, SLOT(processTextMessage(QString))); connect(pSocket, SIGNAL(binaryMessageReceived(QByteArray)), this, SLOT(processBinaryMessage(QByteArray))); connect(pSocket, SIGNAL(disconnected()), this, SLOT(socketDisconnected())); @@ -406,6 +411,7 @@ void tst_QWebSocket::tst_sendTextMessage() QCOMPARE(socket.sendTextMessage(QStringLiteral("1234")), 0); QSignalSpy socketConnectedSpy(&socket, SIGNAL(connected())); + QSignalSpy serverConnectedSpy(&echoServer, SIGNAL(newConnection(QUrl))); QSignalSpy textMessageReceived(&socket, SIGNAL(textMessageReceived(QString))); QSignalSpy textFrameReceived(&socket, SIGNAL(textFrameReceived(QString,bool))); QSignalSpy binaryMessageReceived(&socket, SIGNAL(binaryMessageReceived(QByteArray))); @@ -414,6 +420,7 @@ void tst_QWebSocket::tst_sendTextMessage() QUrl url = QUrl(QStringLiteral("ws://") + echoServer.hostAddress().toString() + QStringLiteral(":") + QString::number(echoServer.port())); + url.setPath("/segment/with spaces"); url.addQueryItem("queryitem", "with encoded characters"); socket.open(url); @@ -422,6 +429,10 @@ void tst_QWebSocket::tst_sendTextMessage() QVERIFY(socketConnectedSpy.wait(500)); QCOMPARE(socketError.count(), 0); QCOMPARE(socket.state(), QAbstractSocket::ConnectedState); + QCOMPARE(serverConnectedSpy.count(), 1); + QList arguments = serverConnectedSpy.takeFirst(); + QUrl urlConnected = arguments.at(0).toUrl(); + QCOMPARE(urlConnected, url); socket.sendTextMessage(QStringLiteral("Hello world!")); @@ -429,7 +440,7 @@ void tst_QWebSocket::tst_sendTextMessage() QCOMPARE(textMessageReceived.count(), 1); QCOMPARE(binaryMessageReceived.count(), 0); QCOMPARE(binaryFrameReceived.count(), 0); - QList arguments = textMessageReceived.takeFirst(); + arguments = textMessageReceived.takeFirst(); QString messageReceived = arguments.at(0).toString(); QCOMPARE(messageReceived, QStringLiteral("Hello world!")); -- cgit v1.2.1