WebSocket: Accept multiple subprotocols
authoryutak@chromium.org <yutak@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 10 Aug 2011 09:07:18 +0000 (09:07 +0000)
committeryutak@chromium.org <yutak@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 10 Aug 2011 09:07:18 +0000 (09:07 +0000)
commit1a464d39a5ddcee9ca46d4ae5a93981deb08ceb3
tree750ceac95e048c3a6ab865aef1c73f436d85b154
parent81f57a8e899eac12944853a23a0a330101b620c8
WebSocket: Accept multiple subprotocols
https://bugs.webkit.org/show_bug.cgi?id=65247

Reviewed by Kent Tamura.

Source/WebCore:

WebSocket constructor should accept an array of subprotocols if hybi-10 protocol is chosen.

Tests: http/tests/websocket/tests/hybi/invalid-subprotocol-characters.html
       http/tests/websocket/tests/hybi/invalid-subprotocols.html
       http/tests/websocket/tests/hybi/multiple-subprotocols.html
       http/tests/websocket/tests/hybi/workers/multiple-subprotocols.html

* bindings/js/JSWebSocketCustom.cpp:
(WebCore::JSWebSocketConstructor::constructJSWebSocket):
If the second argument of WebSocket constructor is an array, build a Vector<String> and
pass it to WebSocket::connect().
* bindings/v8/custom/V8WebSocketCustom.cpp:
(WebCore::V8WebSocket::constructorCallback):
Ditto.
* websockets/WebSocket.cpp:
(WebCore::isValidProtocolCharacter): Added.
(WebCore::isValidProtocolString): Added.
(WebCore::isValidProtocolStringHixie76): Renamed from isValidProtocolString.
(WebCore::joinStrings):
(WebCore::WebSocket::connect):
If an array is provided as a subprotocol, and if hixie-76 is used for this connection, it
must be converted to a string in the same manner as JavaScript's Array.toString() in order
to keep compatibility.
* websockets/WebSocket.h:
Removed m_protocol because it was not used at all.
* websockets/WebSocketChannel.cpp:
(WebCore::WebSocketChannel::disconnect):
WebSocketChannel may be released before connect() is called, thus m_handshake may be null.

LayoutTests:

Add tests to check whether WebSocket accepts multiple subprotocols in constructor.

* http/tests/websocket/tests/hybi/accept-first-subprotocol_wsh.py: Added.
* http/tests/websocket/tests/hybi/invalid-subprotocol-characters-expected.txt: Added.
* http/tests/websocket/tests/hybi/invalid-subprotocol-characters.html: Added.
* http/tests/websocket/tests/hybi/invalid-subprotocols-expected.txt: Added.
* http/tests/websocket/tests/hybi/invalid-subprotocols.html: Added.
* http/tests/websocket/tests/hybi/multiple-subprotocols-expected.txt: Renamed from LayoutTests/http/tests/websocket/tests/hybi/sub-protocol-with-space-expected.txt.
* http/tests/websocket/tests/hybi/multiple-subprotocols.html: Added.
* http/tests/websocket/tests/hybi/sub-protocol-with-space-expected.txt: Removed.
* http/tests/websocket/tests/hybi/sub-protocol-with-space.html:
Removed because hybi-10 does not allow subprotocols containing a space.
* http/tests/websocket/tests/hybi/workers/multiple-subprotocols-expected.txt: Added.
* http/tests/websocket/tests/hybi/workers/multiple-subprotocols.html: Added.
* http/tests/websocket/tests/hybi/workers/resources/multiple-subprotocols.js: Added.
(ws.onopen):
(ws.onmessage):
(ws.onclose):
* http/tests/websocket/tests/hybi/workers/resources/protocol-test_wsh.py: Copied from http/tests/websocket/tests/hybi/protocol-test_wsh.py.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@92757 268f45cc-cd09-0410-ab3c-d52691b4dbfc
19 files changed:
LayoutTests/ChangeLog
LayoutTests/http/tests/websocket/tests/hybi/accept-first-subprotocol_wsh.py [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/invalid-subprotocol-characters-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/invalid-subprotocol-characters.html [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/invalid-subprotocols-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/invalid-subprotocols.html [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/multiple-subprotocols-expected.txt [moved from LayoutTests/http/tests/websocket/tests/hybi/sub-protocol-with-space-expected.txt with 51% similarity]
LayoutTests/http/tests/websocket/tests/hybi/multiple-subprotocols.html [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/sub-protocol-with-space.html [deleted file]
LayoutTests/http/tests/websocket/tests/hybi/workers/multiple-subprotocols-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/workers/multiple-subprotocols.html [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/workers/resources/multiple-subprotocols.js [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/workers/resources/protocol-test_wsh.py [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/bindings/js/JSWebSocketCustom.cpp
Source/WebCore/bindings/v8/custom/V8WebSocketCustom.cpp
Source/WebCore/websockets/WebSocket.cpp
Source/WebCore/websockets/WebSocket.h
Source/WebCore/websockets/WebSocketChannel.cpp