From 15627cc2232bf155d892b630b7e0cb04ce6bbe67 Mon Sep 17 00:00:00 2001
From: Luca Niccoli <lultimouomo@gmail.com>
Date: Wed, 11 Mar 2015 12:26:22 +0100
Subject: [PATCH] Enable websocket tests on Windows

The listening socket must be opened on the loopback interface,
otherwise the test client won't be able to connect.

Also, name resolution can take a lot of time to fail, so we must
wait longer when trying to connect to a non-existing host.

Change-Id: I6d6744bc89e6e851cf49db5ae2c19aa652c0a8a4
Reviewed-by: Liang Qi <liang.qi@theqtcompany.com>
---
 tests/auto/qwebsocket/tst_qwebsocket.cpp | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)

diff --git a/tests/auto/qwebsocket/tst_qwebsocket.cpp b/tests/auto/qwebsocket/tst_qwebsocket.cpp
index 92e969b8..900f3161 100644
--- a/tests/auto/qwebsocket/tst_qwebsocket.cpp
+++ b/tests/auto/qwebsocket/tst_qwebsocket.cpp
@@ -67,7 +67,7 @@ EchoServer::EchoServer(QObject *parent) :
                                             QWebSocketServer::NonSecureMode, this)),
     m_clients()
 {
-    if (m_pWebSocketServer->listen()) {
+    if (m_pWebSocketServer->listen(QHostAddress(QStringLiteral("127.0.0.1")))) {
         connect(m_pWebSocketServer, SIGNAL(newConnection()),
                 this, SLOT(onNewConnection()));
     }
@@ -398,8 +398,6 @@ void tst_QWebSocket::tst_invalidOrigin()
 
 void tst_QWebSocket::tst_sendTextMessage()
 {
-    //TODO: will resolve in another commit
-#ifndef Q_OS_WIN
     EchoServer echoServer;
 
     QWebSocket socket;
@@ -475,13 +473,10 @@ void tst_QWebSocket::tst_sendTextMessage()
     socket.close(QWebSocketProtocol::CloseCodeGoingAway, reason);
     QCOMPARE(socket.closeCode(), QWebSocketProtocol::CloseCodeGoingAway);
     QCOMPARE(socket.closeReason(), reason);
-#endif
 }
 
 void tst_QWebSocket::tst_sendBinaryMessage()
 {
-    //TODO: will resolve in another commit
-#ifndef Q_OS_WIN
     EchoServer echoServer;
 
     QWebSocket socket;
@@ -549,7 +544,6 @@ void tst_QWebSocket::tst_sendBinaryMessage()
     isLastFrame = arguments.at(1).toBool();
     QCOMPARE(frameReceived, QByteArrayLiteral("Hello world!"));
     QVERIFY(isLastFrame);
-#endif
 }
 
 void tst_QWebSocket::tst_errorString()
@@ -565,7 +559,7 @@ void tst_QWebSocket::tst_errorString()
     socket.open(QUrl(QStringLiteral("ws://someserver.on.mars:9999")));
 
     if (errorSpy.count() == 0)
-        errorSpy.wait();
+        errorSpy.wait(500);
     QCOMPARE(errorSpy.count(), 1);
     QList<QVariant> arguments = errorSpy.takeFirst();
     QAbstractSocket::SocketError socketError =
-- 
GitLab