Diff
Modified: trunk/LayoutTests/ChangeLog (94281 => 94282)
--- trunk/LayoutTests/ChangeLog 2011-09-01 09:40:47 UTC (rev 94281)
+++ trunk/LayoutTests/ChangeLog 2011-09-01 09:58:52 UTC (rev 94282)
@@ -1,3 +1,15 @@
+2011-09-01 Yuta Kitamura <[email protected]>
+
+ WebSocket: Fix bufferedAmount after WebSocket is closed
+ https://bugs.webkit.org/show_bug.cgi?id=67363
+
+ Reviewed by Kent Tamura.
+
+ * http/tests/websocket/tests/hybi/bufferedAmount-after-close-expected.txt:
+ * http/tests/websocket/tests/hybi/bufferedAmount-after-close.html:
+ Try to send messages having various lengths to make sure we correctly calculate
+ the framing overhead.
+
2011-09-01 Ryosuke Niwa <[email protected]>
Temporarily skip a test that started failing after r94274.
Modified: trunk/LayoutTests/http/tests/websocket/tests/hybi/bufferedAmount-after-close-expected.txt (94281 => 94282)
--- trunk/LayoutTests/http/tests/websocket/tests/hybi/bufferedAmount-after-close-expected.txt 2011-09-01 09:40:47 UTC (rev 94281)
+++ trunk/LayoutTests/http/tests/websocket/tests/hybi/bufferedAmount-after-close-expected.txt 2011-09-01 09:58:52 UTC (rev 94282)
@@ -6,8 +6,20 @@
Closed.
PASS ws.readyState is 3
PASS ws.bufferedAmount is 0
-PASS ws.send('send to closed socket') is false
-PASS ws.bufferedAmount is 23
+PASS ws.send(messageToSend) is false
+PASS bufferedAmountDifference is 27
+PASS ws.send(messageToSend) is false
+PASS bufferedAmountDifference is 6
+PASS ws.send(messageToSend) is false
+PASS bufferedAmountDifference is 7
+PASS ws.send(messageToSend) is false
+PASS bufferedAmountDifference is 131
+PASS ws.send(messageToSend) is false
+PASS bufferedAmountDifference is 134
+PASS ws.send(messageToSend) is false
+PASS bufferedAmountDifference is 65543
+PASS ws.send(messageToSend) is false
+PASS bufferedAmountDifference is 65550
PASS successfullyParsed is true
TEST COMPLETE
Modified: trunk/LayoutTests/http/tests/websocket/tests/hybi/bufferedAmount-after-close.html (94281 => 94282)
--- trunk/LayoutTests/http/tests/websocket/tests/hybi/bufferedAmount-after-close.html 2011-09-01 09:40:47 UTC (rev 94281)
+++ trunk/LayoutTests/http/tests/websocket/tests/hybi/bufferedAmount-after-close.html 2011-09-01 09:58:52 UTC (rev 94282)
@@ -14,6 +14,14 @@
if (window.layoutTestController)
layoutTestController.overridePreference("WebKitHixie76WebSocketProtocolEnabled", 0);
+function createStringWithLength(length)
+{
+ var string = 'x';
+ while (string.length < length)
+ string = string + string;
+ return string.substring(0, length);
+}
+
var ws = new WebSocket("ws://localhost:8880/websocket/tests/hybi/simple");
ws._onopen_ = function()
@@ -27,13 +35,34 @@
debug("Closed.");
shouldBe("ws.readyState", "3");
shouldBe("ws.bufferedAmount", "0");
- shouldBeFalse("ws.send('send to closed socket')");
+
+ var baseOverhead = 2 + 4; // Base header size and masking key size.
+ testBufferedAmount('send to closed socket', 21 + baseOverhead);
+ testBufferedAmount('', baseOverhead);
+ testBufferedAmount('a', 1 + baseOverhead);
+ testBufferedAmount(createStringWithLength(125), 125 + baseOverhead);
+ testBufferedAmount(createStringWithLength(126), 126 + baseOverhead + 2); // With 16-bit extended payload length field.
+ testBufferedAmount(createStringWithLength(0xFFFF), 0xFFFF + baseOverhead + 2);
+ testBufferedAmount(createStringWithLength(0x10000), 0x10000 + baseOverhead + 8); // With 64-bit extended payload length field.
+
+ finishJSTest();
+};
+
+var messageToSend;
+var bufferedAmountDifference;
+
+function testBufferedAmount(message, expectedBufferedAmountDifference)
+{
// If the connection is closed, bufferedAmount attribute's value will only
// increase with each call to the send() method.
// (the number does not reset to zero once the connection closes).
- shouldBe("ws.bufferedAmount", "23");
- finishJSTest();
-};
+ messageToSend = message;
+ var bufferedAmountBeforeSend = ws.bufferedAmount;
+ shouldBeFalse("ws.send(messageToSend)");
+ var bufferedAmountAfterSend = ws.bufferedAmount;
+ bufferedAmountDifference = bufferedAmountAfterSend - bufferedAmountBeforeSend;
+ shouldEvaluateTo("bufferedAmountDifference", expectedBufferedAmountDifference);
+}
var successfullyParsed = true;
</script>
Modified: trunk/Source/WebCore/ChangeLog (94281 => 94282)
--- trunk/Source/WebCore/ChangeLog 2011-09-01 09:40:47 UTC (rev 94281)
+++ trunk/Source/WebCore/ChangeLog 2011-09-01 09:58:52 UTC (rev 94282)
@@ -1,3 +1,17 @@
+2011-09-01 Yuta Kitamura <[email protected]>
+
+ WebSocket: Fix bufferedAmount after WebSocket is closed
+ https://bugs.webkit.org/show_bug.cgi?id=67363
+
+ Reviewed by Kent Tamura.
+
+ Test: http/tests/websocket/tests/hybi/bufferedAmount-after-close.html (updated)
+
+ * websockets/WebSocket.cpp:
+ (WebCore::WebSocket::send):
+ (WebCore::WebSocket::getFramingOverhead):
+ * websockets/WebSocket.h:
+
2011-09-01 Keishi Hattori <[email protected]>
Rename colorSelected to didChooseColor
Modified: trunk/Source/WebCore/websockets/WebSocket.cpp (94281 => 94282)
--- trunk/Source/WebCore/websockets/WebSocket.cpp 2011-09-01 09:40:47 UTC (rev 94281)
+++ trunk/Source/WebCore/websockets/WebSocket.cpp 2011-09-01 09:58:52 UTC (rev 94282)
@@ -254,7 +254,8 @@
}
// No exception is raised if the connection was once established but has subsequently been closed.
if (m_state == CLOSING || m_state == CLOSED) {
- m_bufferedAmountAfterClose += message.utf8().length() + 2; // 2 for frameing
+ size_t payloadSize = message.utf8().length();
+ m_bufferedAmountAfterClose += payloadSize + getFramingOverhead(payloadSize);
return false;
}
// FIXME: check message is valid utf8.
@@ -465,6 +466,24 @@
return &m_eventTargetData;
}
+size_t WebSocket::getFramingOverhead(size_t payloadSize)
+{
+ static const size_t hixie76FramingOverhead = 2; // Payload is surrounded by 0x00 and 0xFF.
+ if (m_useHixie76Protocol)
+ return hixie76FramingOverhead;
+
+ static const size_t hybiBaseFramingOverhead = 2; // Every frame has at least two-byte header.
+ static const size_t hybiMaskingKeyLength = 4; // Every frame from client must have masking key.
+ static const size_t minimumPayloadSizeWithTwoByteExtendedPayloadLength = 126;
+ static const size_t minimumPayloadSizeWithEightByteExtendedPayloadLength = 0x10000;
+ size_t overhead = hybiBaseFramingOverhead + hybiMaskingKeyLength;
+ if (payloadSize >= minimumPayloadSizeWithEightByteExtendedPayloadLength)
+ overhead += 8;
+ else if (payloadSize >= minimumPayloadSizeWithTwoByteExtendedPayloadLength)
+ overhead += 2;
+ return overhead;
+}
+
} // namespace WebCore
#endif
Modified: trunk/Source/WebCore/websockets/WebSocket.h (94281 => 94282)
--- trunk/Source/WebCore/websockets/WebSocket.h 2011-09-01 09:40:47 UTC (rev 94281)
+++ trunk/Source/WebCore/websockets/WebSocket.h 2011-09-01 09:58:52 UTC (rev 94282)
@@ -113,6 +113,8 @@
virtual EventTargetData* eventTargetData();
virtual EventTargetData* ensureEventTargetData();
+ size_t getFramingOverhead(size_t payloadSize);
+
enum BinaryType {
BinaryTypeBlob,
BinaryTypeArrayBuffer