Commit c4038f34 authored by yhirano@chromium.org's avatar yhirano@chromium.org

Add WebSocket unittests.

Add unittests for WebCore::WebSocket class.

BUG=NONE

Review URL: https://codereview.chromium.org/298893008

git-svn-id: svn://svn.chromium.org/blink/trunk@175096 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 7a7998fb
......@@ -951,6 +951,7 @@
'websockets/WebSocketExtensionDispatcherTest.cpp',
'websockets/WebSocketExtensionParserTest.cpp',
'websockets/WebSocketPerMessageDeflateTest.cpp',
'websockets/WebSocketTest.cpp',
],
},
}
......@@ -61,8 +61,6 @@
#include "wtf/text/StringBuilder.h"
#include "wtf/text/WTFString.h"
using namespace std;
namespace WebCore {
WebSocket::EventQueue::EventQueue(EventTarget* target)
......@@ -172,7 +170,7 @@ static inline bool isValidSubprotocolCharacter(UChar character)
return character >= minimumProtocolCharacter && character <= maximumProtocolCharacter && isNotSeparator;
}
static bool isValidSubprotocolString(const String& protocol)
bool WebSocket::isValidSubprotocolString(const String& protocol)
{
if (protocol.isEmpty())
return false;
......@@ -210,8 +208,8 @@ static String joinStrings(const Vector<String>& strings, const char* separator)
static unsigned long saturateAdd(unsigned long a, unsigned long b)
{
if (numeric_limits<unsigned long>::max() - a < b)
return numeric_limits<unsigned long>::max();
if (std::numeric_limits<unsigned long>::max() - a < b)
return std::numeric_limits<unsigned long>::max();
return a + b;
}
......@@ -220,7 +218,7 @@ static void setInvalidStateErrorForSendMethod(ExceptionState& exceptionState)
exceptionState.throwDOMException(InvalidStateError, "Still in CONNECTING state.");
}
const char* WebSocket::subProtocolSeperator()
const char* WebSocket::subprotocolSeperator()
{
return ", ";
}
......@@ -318,7 +316,7 @@ void WebSocket::connect(const String& url, const Vector<String>& protocols, Exce
return;
}
m_channel = WebSocketChannel::create(executionContext(), this);
m_channel = createChannel(executionContext(), this);
for (size_t i = 0; i < protocols.size(); ++i) {
if (!isValidSubprotocolString(protocols[i])) {
......@@ -340,7 +338,7 @@ void WebSocket::connect(const String& url, const Vector<String>& protocols, Exce
String protocolString;
if (!protocols.isEmpty())
protocolString = joinStrings(protocols, subProtocolSeperator());
protocolString = joinStrings(protocols, subprotocolSeperator());
if (!m_channel->connect(m_url, protocolString)) {
m_state = CLOSED;
......
......@@ -51,11 +51,11 @@ namespace WebCore {
class Blob;
class ExceptionState;
class WebSocket FINAL : public RefCountedWillBeRefCountedGarbageCollected<WebSocket>, public ScriptWrappable, public EventTargetWithInlineData, public ActiveDOMObject, public WebSocketChannelClient {
class WebSocket : public RefCountedWillBeRefCountedGarbageCollected<WebSocket>, public ScriptWrappable, public EventTargetWithInlineData, public ActiveDOMObject, public WebSocketChannelClient {
REFCOUNTED_EVENT_TARGET(WebSocket);
WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(WebSocket);
public:
static const char* subProtocolSeperator();
static const char* subprotocolSeperator();
// WebSocket instances must be used with a wrapper since this class's
// lifetime management is designed assuming the V8 holds a ref on it while
// hasPendingActivity() returns true.
......@@ -126,6 +126,11 @@ public:
virtual void trace(Visitor*) OVERRIDE;
static bool isValidSubprotocolString(const String&);
protected:
explicit WebSocket(ExecutionContext*);
private:
// FIXME: This should inherit WebCore::EventQueue.
class EventQueue FINAL : public RefCountedWillBeGarbageCollectedFinalized<EventQueue> {
......@@ -177,7 +182,12 @@ private:
WebSocketSendTypeMax,
};
explicit WebSocket(ExecutionContext*);
// This function is virtual for unittests.
// FIXME: Move WebSocketChannel::create here.
virtual PassRefPtrWillBeRawPtr<WebSocketChannel> createChannel(ExecutionContext* context, WebSocketChannelClient* client)
{
return WebSocketChannel::create(context, client);
}
// Adds a console message with JSMessageSource and ErrorMessageLevel.
void logError(const String& message);
......
......@@ -533,7 +533,7 @@ bool WebSocketHandshake::checkResponseHeaders()
return false;
}
Vector<String> result;
m_clientProtocol.split(String(WebSocket::subProtocolSeperator()), result);
m_clientProtocol.split(String(WebSocket::subprotocolSeperator()), result);
if (!result.contains(serverWebSocketProtocol)) {
m_failureReason = formatHandshakeFailureReason("'Sec-WebSocket-Protocol' header value '" + serverWebSocketProtocol + "' in response does not match any of sent values");
return false;
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment