[WebSocket] Ignore incoming message in CLOSING state

https://bugs.webkit.org/show_bug.cgi?id=85934

Patch by Lamarque V. Souza <Lamarque.Souza@basyskom.com> on 2013-04-09
Reviewed by Kent Tamura.

Source/WebCore:

Change WebSocket implementation to suit the new WebSocket API, which
states that we should ignore messages in CLOSING state.

No new tests, updating existing tests.

* Modules/websockets/WebSocket.cpp:
(WebCore::WebSocket::didReceiveMessage):

LayoutTests:

* http/tests/websocket/tests/hybi/client-close-expected.txt: Rebaseline.
* http/tests/websocket/tests/hybi/client-close.html: Change expected results.
* http/tests/websocket/tests/hybi/client-close_wsh.py: Embed message in close frame
instead of using regular message sending call.
* http/tests/websocket/tests/hybi/fragmented-frames.html: Call WebSocket.close()
only after receiving all messages from server.
* http/tests/websocket/tests/hybi/unmasked-frames.html: Remove extra
WebSocket.close() call that caused regression.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@148019 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 88deaa45
2013-04-09 Lamarque V. Souza <Lamarque.Souza@basyskom.com>
[WebSocket] Ignore incoming message in CLOSING state
https://bugs.webkit.org/show_bug.cgi?id=85934
Reviewed by Kent Tamura.
* http/tests/websocket/tests/hybi/client-close-expected.txt: Rebaseline.
* http/tests/websocket/tests/hybi/client-close.html: Change expected results.
* http/tests/websocket/tests/hybi/client-close_wsh.py: Embed message in close frame
instead of using regular message sending call.
* http/tests/websocket/tests/hybi/fragmented-frames.html: Call WebSocket.close()
only after receiving all messages from server.
* http/tests/websocket/tests/hybi/unmasked-frames.html: Remove extra
WebSocket.close() call that caused regression.
2013-04-09 Raphael Kubo da Costa <raphael.kubo.da.costa@intel.com>
[EFL] Move tables/mozilla_expected_failures/bugs/bug89315.html's expectations to efl/.
WebSocket: Test client-initiated close.
WebSocket: Test client-initiated close. After WebSocket.close() any message from server must be discarded by WebSocket stack according to the new WebSocket API. See http://webkit.org/b/85934.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
Connected
Received: close_frame[:2]='\x88\x80'
Closed
PASS receivedMessage is "close_frame[:2]='\\x88\\x80'"
PASS receivedMessage is undefined.
PASS closeEvent.reason is "close_frame[:2]='\\x88\\x80'"
PASS closeEvent.wasClean is true
PASS successfullyParsed is true
......
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<!DOCTYPE HTML>
<html>
<head>
<script src="../../../../js-test-resources/js-test-pre.js"></script>
<script src="/js-test-resources/js-test-pre.js"></script>
</head>
<body>
<div id="description"></div>
<div id="console"></div>
<script type="text/javascript">
description("WebSocket: Test client-initiated close.");
description("WebSocket: Test client-initiated close. After WebSocket.close() any message from server must be discarded by WebSocket stack according to the new WebSocket API. See http://webkit.org/b/85934.");
window.jsTestIsAsync = true;
......@@ -23,7 +23,7 @@ ws.onopen = function()
ws.onmessage = function(messageEvent)
{
debug("Received: " + messageEvent.data);
debug("Message should have been ignored: " + messageEvent.data);
receivedMessage = messageEvent.data;
};
......@@ -31,7 +31,8 @@ ws.onclose = function(event)
{
debug("Closed");
closeEvent = event;
shouldBeEqualToString("receivedMessage", "close_frame[:2]='\\x88\\x80'");
shouldBeUndefined("receivedMessage");
shouldBeEqualToString("closeEvent.reason", "close_frame[:2]='\\x88\\x80'");
shouldBeTrue("closeEvent.wasClean");
finishJSTest();
};
......
from mod_pywebsocket import msgutil
import struct
from mod_pywebsocket import msgutil
from mod_pywebsocket import stream
def web_socket_do_extra_handshake(request):
pass
......@@ -9,9 +11,12 @@ def web_socket_transfer_data(request):
# Wait for a close frame sent from the client.
close_frame = request.ws_stream.receive_bytes(6)
msgutil.send_message(request, 'Client should ignore this message')
# Send only first two bytes of the received frame. The remaining four bytes are
# "masking key", which changes every time the test runs.
msgutil.send_message(request, 'close_frame[:2]=%r' % close_frame[:2])
data = struct.pack('!H', 1000) + 'close_frame[:2]=%r' % close_frame[:2]
request.connection.write(stream.create_close_frame(data))
# If the following assertion fails, AssertionError will be raised,
# which will prevent pywebsocket from sending a close frame.
......
<!DOCTYPE HTML>
<html>
<head>
<script src="../../../../js-test-resources/js-test-pre.js"></script>
<script src="/js-test-resources/js-test-pre.js"></script>
</head>
<body>
<div id="description"></div>
......@@ -20,7 +20,6 @@ var actualMessages = [];
ws.onopen = function()
{
debug("onopen() was called.");
ws.close();
};
ws.onmessage = function(event)
......@@ -28,6 +27,9 @@ ws.onmessage = function(event)
var message = event.data;
debug("onmessage() was called. (message = \"" + message + "\")");
actualMessages.push(message);
if (actualMessages.length == 3)
ws.close();
};
ws.onclose = function(event)
......
<!DOCTYPE HTML>
<html>
<head>
<script src="../../../../js-test-resources/js-test-pre.js"></script>
<script src="/js-test-resources/js-test-pre.js"></script>
</head>
<body>
<div id="description"></div>
......@@ -20,7 +20,6 @@ var actualMessages = [];
ws.onopen = function()
{
debug("onopen() was called.");
ws.close();
};
ws.onmessage = function(event)
......
2013-04-09 Lamarque V. Souza <Lamarque.Souza@basyskom.com>
[WebSocket] Ignore incoming message in CLOSING state
https://bugs.webkit.org/show_bug.cgi?id=85934
Reviewed by Kent Tamura.
Change WebSocket implementation to suit the new WebSocket API, which
states that we should ignore messages in CLOSING state.
No new tests, updating existing tests.
* Modules/websockets/WebSocket.cpp:
(WebCore::WebSocket::didReceiveMessage):
2013-04-09 Seokju Kwon <seokju.kwon@gmail.com>
Web Inspector: Add Localized strings after r144154 and r135127
......@@ -513,7 +513,7 @@ void WebSocket::didConnect()
void WebSocket::didReceiveMessage(const String& msg)
{
LOG(Network, "WebSocket %p didReceiveMessage() Text message '%s'", this, msg.utf8().data());
if (m_state != OPEN && m_state != CLOSING)
if (m_state != OPEN)
return;
ASSERT(scriptExecutionContext());
dispatchEvent(MessageEvent::create(msg, SecurityOrigin::create(m_url)->toString()));
......
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