bufferedAmount calculation is wrong in CLOSING and CLOSED state.
https://bugs.webkit.org/show_bug.cgi?id=73404
Patch by Takashi Toyoshima <toyoshim@chromium.org> on 2011-12-01
Reviewed by Kent Tamura.
Source/WebCore:
WebSocket::bufferedAmount() must return buffered frame size including
disposed frames which are passed via send() calls after close().
Old implementation had a problem at CLOSING state. Buffered frame size
was added to m_bufferedAmountAfterClose at close(). But the function
returns the sum of m_bufferedAmountAfterClose and internally buffered
frame size, or m_channel->bufferedAmount(). So, buffered frames was
double counted.
In new implementation, m_bufferedAmount always represents buffered
frame size and m_bufferedAmountAfterClose does disposed frame size.
As a result, bufferedAmount() implementation become just to return the
sum of m_bufferedAmount and m_bufferedAmountAfterClose.
Test: http/tests/websocket/tests/hybi/bufferedAmount-after-close-in-busy.html
* websockets/WebSocket.cpp: Implement new bufferedAmount handling.
(WebCore::saturateAdd):
(WebCore::WebSocket::WebSocket):
(WebCore::WebSocket::send):
(WebCore::WebSocket::close):
(WebCore::WebSocket::bufferedAmount):
(WebCore::WebSocket::didUpdateBufferedAmount):
(WebCore::WebSocket::didClose):
* websockets/WebSocket.h:
LayoutTests:
Add a layout test to check the WebSocket bufferedAmount property.
This test close the socket channel when it is busy and buffer some
message frames, then check the property's value in CLOSING and CLOSED
state.
* http/tests/websocket/tests/hybi/bufferedAmount-after-close-in-busy-expected.txt: Added.
* http/tests/websocket/tests/hybi/bufferedAmount-after-close-in-busy.html: Added.
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@101730
268f45cc-cd09-0410-ab3c-
d52691b4dbfc