Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(916)

Unified Diff: third_party/WebKit/Source/modules/websockets/DocumentWebSocketChannelTest.cpp

Issue 1574213003: [ABANDONED] Use new Websocket SendBlob IPC from renderer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@websocket_blob_send_sender
Patch Set: Comment that bufferedAmount may be temporarily too low. Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/modules/websockets/DocumentWebSocketChannelTest.cpp
diff --git a/third_party/WebKit/Source/modules/websockets/DocumentWebSocketChannelTest.cpp b/third_party/WebKit/Source/modules/websockets/DocumentWebSocketChannelTest.cpp
index f94491934e013e1218731b6381a380f1f652722f..cfb4b5502d6ac236b3ee7c3781c89895bc92f3ad 100644
--- a/third_party/WebKit/Source/modules/websockets/DocumentWebSocketChannelTest.cpp
+++ b/third_party/WebKit/Source/modules/websockets/DocumentWebSocketChannelTest.cpp
@@ -82,6 +82,7 @@ public:
MOCK_METHOD4(connect, void(const WebURL&, const WebVector<WebString>&, const WebSecurityOrigin&, WebSocketHandleClient*));
MOCK_METHOD4(send, void(bool, WebSocketHandle::MessageType, const char*, size_t));
+ MOCK_METHOD2(sendBlob, void(const blink::WebString&, uint64_t));
MOCK_METHOD1(flowControl, void(int64_t));
MOCK_METHOD2(close, void(unsigned short, const WebString&));
};
@@ -148,6 +149,13 @@ public:
unsigned long m_sumOfConsumedBufferedAmount;
};
+// The WebSocket protocol and API ignores the type of the Blob, so put a
+// default value in that field.
+PassRefPtr<BlobDataHandle> createBlob(const String& uuid, long long size)
+{
+ return BlobDataHandle::create(uuid, "unknown/unknown", size);
+}
+
MATCHER_P2(MemEq, p, len,
std::string("pointing to memory")
+ (negation ? " not" : "")
@@ -463,7 +471,110 @@ TEST_F(DocumentWebSocketChannelTest, sendBinaryInArrayBufferNonLatin1UTF8Continu
EXPECT_EQ(18ul, m_sumOfConsumedBufferedAmount);
}
-// FIXME: Add tests for WebSocketChannel::send(PassRefPtr<BlobDataHandle>)
+TEST_F(DocumentWebSocketChannelTest, sendSingleBlob)
+{
+ connect();
+ EXPECT_CALL(*handle(), sendBlob(WebString("uuid"), 10));
+ handleClient()->didReceiveFlowControl(handle(), 16);
+ channel()->send(createBlob("uuid", 10));
+}
+
+TEST_F(DocumentWebSocketChannelTest, sendTwoBlobs)
+{
+ connect();
+ Checkpoint checkpoint;
+ {
+ InSequence s;
+ EXPECT_CALL(*handle(), sendBlob(WebString("uuid1"), 11));
+ EXPECT_CALL(checkpoint, Call(1));
+ EXPECT_CALL(*handle(), sendBlob(WebString("uuid2"), 12));
+ }
+ EXPECT_CALL(*channelClient(), didConsumeBufferedAmount(_))
+ .Times(AnyNumber());
+ handleClient()->didReceiveFlowControl(handle(), 32);
+ channel()->send(createBlob("uuid1", 11));
+ channel()->send(createBlob("uuid2", 12));
+ checkpoint.Call(1);
+ handleClient()->didCompleteSendingBlob(handle());
+}
+
+TEST_F(DocumentWebSocketChannelTest, flowControlReflectedInBufferedAmount)
+{
+ connect();
+ EXPECT_CALL(*handle(), sendBlob(WebString("uuid"), 256));
+ EXPECT_CALL(*channelClient(), didConsumeBufferedAmount(_))
+ .Times(AnyNumber());
+ handleClient()->didReceiveFlowControl(handle(), 128);
+ channel()->send(createBlob("uuid", 256));
+ EXPECT_EQ(0u, m_sumOfConsumedBufferedAmount);
+ handleClient()->didReceiveFlowControl(handle(), 128);
+ EXPECT_EQ(128u, m_sumOfConsumedBufferedAmount);
+ handleClient()->didCompleteSendingBlob(handle());
+ EXPECT_EQ(256u, m_sumOfConsumedBufferedAmount);
+}
+
+// Verifies that Blobs respect queue ordering.
+TEST_F(DocumentWebSocketChannelTest, sendTextThenBlob)
+{
+ connect();
+ Checkpoint checkpoint;
+ {
+ InSequence s;
+ EXPECT_CALL(checkpoint, Call(1));
+ EXPECT_CALL(*handle(), send(true, WebSocketHandle::MessageTypeText, MemEq("foo", 3), 3));
+ EXPECT_CALL(*handle(), sendBlob(WebString("uuid"), 16));
+ }
+ EXPECT_CALL(*channelClient(), didConsumeBufferedAmount(_))
+ .Times(AnyNumber());
+ channel()->send("foo");
+ channel()->send(createBlob("uuid", 16));
+ checkpoint.Call(1);
+ handleClient()->didReceiveFlowControl(handle(), 128);
+}
+
+// Verifies that "Blob sending mode" is exited correctly.
+TEST_F(DocumentWebSocketChannelTest, sendBlobThenText)
+{
+ connect();
+ Checkpoint checkpoint;
+ {
+ InSequence s;
+ EXPECT_CALL(*handle(), sendBlob(WebString("uuid"), 16));
+ EXPECT_CALL(checkpoint, Call(1));
+ EXPECT_CALL(*handle(), send(true, WebSocketHandle::MessageTypeText, MemEq("foo", 3), 3));
+ }
+ EXPECT_CALL(*channelClient(), didConsumeBufferedAmount(_))
+ .Times(AnyNumber());
+ handleClient()->didReceiveFlowControl(handle(), 128);
+ channel()->send(createBlob("uuid", 16));
+ channel()->send("foo");
+ checkpoint.Call(1);
+ // Exits "Blob sending mode" and allows text message "foo" to be sent.
+ handleClient()->didCompleteSendingBlob(handle());
+}
+
+// Verifies that other messages are queued during "Blob sending mode", and that
+// flow control messages do not cause them to be sent prematurely.
+TEST_F(DocumentWebSocketChannelTest, sendLargeBlobThenText)
+{
+ connect();
+ Checkpoint checkpoint;
+ {
+ InSequence s;
+ EXPECT_CALL(*handle(), sendBlob(WebString("uuid"), 256));
+ EXPECT_CALL(checkpoint, Call(1));
+ EXPECT_CALL(*handle(), send(true, WebSocketHandle::MessageTypeText, MemEq("foo", 3), 3));
+ }
+ EXPECT_CALL(*channelClient(), didConsumeBufferedAmount(_))
+ .Times(AnyNumber());
+ handleClient()->didReceiveFlowControl(handle(), 128);
+ channel()->send(createBlob("uuid", 256));
+ handleClient()->didReceiveFlowControl(handle(), 128);
+ handleClient()->didReceiveFlowControl(handle(), 128);
+ channel()->send("foo");
+ checkpoint.Call(1);
+ handleClient()->didCompleteSendingBlob(handle());
+}
TEST_F(DocumentWebSocketChannelTest, receiveText)
{

Powered by Google App Engine
This is Rietveld 408576698