164cc5bf22a97f9dad785be68638ddee1b2aa2c3
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / LayoutTests / http / tests / websocket / unmasked-frames_wsh.py
1 from mod_pywebsocket import common
2 from mod_pywebsocket import handshake
3 from mod_pywebsocket import stream
4 from mod_pywebsocket import msgutil
5
6
7 def web_socket_do_extra_handshake(request):
8     pass
9
10
11 def web_socket_transfer_data(request):
12     # pywebsocket does not mask message by default. We need to build a frame manually to mask it.
13     request.connection.write(stream.create_text_frame('First message', mask=False))
14
15     request.connection.write(stream.create_text_frame('Fragmented ', opcode=common.OPCODE_TEXT, fin=0, mask=False))
16     request.connection.write(stream.create_text_frame('message', opcode=common.OPCODE_CONTINUATION, fin=1, mask=False))
17
18     request.connection.write(stream.create_text_frame('', mask=False))
19
20     msgutil.send_message(request, 'END')
21
22     # Wait for the client to start closing handshake.
23     # To receive a close frame, we must use an internal method of request.ws_stream.
24     opcode, payload, final, reserved1, reserved2, reserved3 = request.ws_stream._receive_frame()
25     assert opcode == common.OPCODE_CLOSE
26     assert final
27     assert not reserved1
28     assert not reserved2
29     assert not reserved3
30
31     # Send a masked close frame. Clients should be able to handle this frame and
32     # the WebSocket object should be closed cleanly.
33     request.connection.write(stream.create_close_frame('', mask=False))
34
35     raise handshake.AbortedByUserException('Abort the connection') # Prevents pywebsocket from starting its own closing handshake.