diff options
author | ricea <ricea@chromium.org> | 2016-01-05 20:57:38 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-01-06 04:58:25 +0000 |
commit | 5858a5056b4fe0f4777b99843e2fb32a37846910 (patch) | |
tree | 4b344a1ded2f9f2d7d3a6e39fd3f4b43a9cf44f3 /net/websockets | |
parent | f9a59bf85acce48993228ed1704244a12570e5eb (diff) | |
download | chromium_src-5858a5056b4fe0f4777b99843e2fb32a37846910.zip chromium_src-5858a5056b4fe0f4777b99843e2fb32a37846910.tar.gz chromium_src-5858a5056b4fe0f4777b99843e2fb32a37846910.tar.bz2 |
Add current_send_quota() accessor to WebSocketChannel
Make the browser's idea of how much quota it has given the renderer
visible outside net::WebSocketChannel. This will be used for
browser-side Blob sending functionality.
See design doc at
https://docs.google.com/document/d/1CDiXB9pBumhFVVfmIn1CRI6v6byxyqWu2urEE9xp714/edit
BUG=571656
TEST=net_unittests
Review URL: https://codereview.chromium.org/1549453003
Cr-Commit-Position: refs/heads/master@{#367777}
Diffstat (limited to 'net/websockets')
-rw-r--r-- | net/websockets/websocket_channel.h | 6 | ||||
-rw-r--r-- | net/websockets/websocket_channel_test.cc | 25 |
2 files changed, 30 insertions, 1 deletions
diff --git a/net/websockets/websocket_channel.h b/net/websockets/websocket_channel.h index a564270..114bb5e 100644 --- a/net/websockets/websocket_channel.h +++ b/net/websockets/websocket_channel.h @@ -98,6 +98,12 @@ class NET_EXPORT WebSocketChannel { // processing to OnClosingHandshake() if necessary. void StartClosingHandshake(uint16_t code, const std::string& reason); + // Returns the current send quota. This value is unsafe to use outside of the + // browser IO thread because it changes asynchronously. The value is only + // valid for the execution of the current Task or until SendFrame() is called, + // whichever happens sooner. + int current_send_quota() const { return current_send_quota_; } + // Starts the connection process, using a specified creator callback rather // than the default. This is exposed for testing. void SendAddChannelRequestForTesting( diff --git a/net/websockets/websocket_channel_test.cc b/net/websockets/websocket_channel_test.cc index 5413444..fabd81d 100644 --- a/net/websockets/websocket_channel_test.cc +++ b/net/websockets/websocket_channel_test.cc @@ -5,8 +5,8 @@ #include "net/websockets/websocket_channel.h" #include <limits.h> +#include <stddef.h> #include <string.h> - #include <iostream> #include <iterator> #include <string> @@ -3421,5 +3421,28 @@ TEST_F(WebSocketChannelStreamTimeoutTest, ConnectionCloseTimesOut) { completion.WaitForResult(); } +// Verify that current_send_quota() returns a non-zero value for a newly +// connected channel. +TEST_F(WebSocketChannelTest, CurrentSendQuotaNonZero) { + CreateChannelAndConnectSuccessfully(); + EXPECT_GT(channel_->current_send_quota(), 0); +} + +// Verify that current_send_quota() is updated when SendFrame() is called. +TEST_F(WebSocketChannelTest, CurrentSendQuotaUpdated) { + const int kMessageSize = 5; + set_stream(make_scoped_ptr(new WriteableFakeWebSocketStream)); + CreateChannelAndConnectSuccessfully(); + + int initial_send_quota = channel_->current_send_quota(); + EXPECT_GE(initial_send_quota, kMessageSize); + + channel_->SendFrame( + true, WebSocketFrameHeader::kOpCodeText, + std::vector<char>(static_cast<size_t>(kMessageSize), 'a')); + int new_send_quota = channel_->current_send_quota(); + EXPECT_EQ(kMessageSize, initial_send_quota - new_send_quota); +} + } // namespace } // namespace net |