summaryrefslogtreecommitdiffstats
path: root/net/socket_stream/socket_stream_unittest.cc
diff options
context:
space:
mode:
authortyoshino@chromium.org <tyoshino@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-04-03 17:13:02 +0000
committertyoshino@chromium.org <tyoshino@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-04-03 17:13:02 +0000
commit21dc4c2c1747a71efebb36067577df3af367d01f (patch)
treea5416176d140c293448e43c736b31a44f840d2ab /net/socket_stream/socket_stream_unittest.cc
parent31782c03a4a6746e8fc194ecf036b203a1942e55 (diff)
downloadchromium_src-21dc4c2c1747a71efebb36067577df3af367d01f.zip
chromium_src-21dc4c2c1747a71efebb36067577df3af367d01f.tar.gz
chromium_src-21dc4c2c1747a71efebb36067577df3af367d01f.tar.bz2
Clean up SocketStream send operation by utilizing DrainableIOBuffer.
- Remove unnecessary variables, write_buf_, write_buf_offset_ and write_buf_size_, and utilize the DrainableIOBuffer |current_write_buf_| to do what they were doing. - Use waiting_for_write_completion_ instead of current_write_buf_ to remember whether Write operation is ongoing or not. - Make DidSendData void and return OK outside it. - In SendData(), now max_pending_send_allowed_ check is done even if current_write_buf_ (formerly write_buf_) is NULL - Rewrite comments. TEST=net_unittests --gtest_filter='SocketStreamTest.*' Review URL: https://chromiumcodereview.appspot.com/12742018 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@192080 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/socket_stream/socket_stream_unittest.cc')
-rw-r--r--net/socket_stream/socket_stream_unittest.cc44
1 files changed, 44 insertions, 0 deletions
diff --git a/net/socket_stream/socket_stream_unittest.cc b/net/socket_stream/socket_stream_unittest.cc
index ed3aa9b..e98e0df 100644
--- a/net/socket_stream/socket_stream_unittest.cc
+++ b/net/socket_stream/socket_stream_unittest.cc
@@ -258,6 +258,13 @@ class SocketStreamTest : public PlatformTest {
event->socket->Close();
}
+ virtual void DoFailByTooBigDataAndClose(SocketStreamEvent* event) {
+ std::string frame(event->number + 1, 0x00);
+ VLOG(1) << event->number;
+ EXPECT_FALSE(event->socket->SendData(&frame[0], frame.size()));
+ event->socket->Close();
+ }
+
virtual int DoSwitchToSpdyTest(SocketStreamEvent* event) {
return ERR_PROTOCOL_SWITCHED;
}
@@ -363,6 +370,43 @@ TEST_F(SocketStreamTest, CloseFlushPendingWrite) {
EXPECT_EQ(SocketStreamEvent::EVENT_CLOSE, events[7].event_type);
}
+TEST_F(SocketStreamTest, ExceedMaxPendingSendAllowed) {
+ TestCompletionCallback test_callback;
+
+ scoped_ptr<SocketStreamEventRecorder> delegate(
+ new SocketStreamEventRecorder(test_callback.callback()));
+ delegate->SetOnConnected(base::Bind(
+ &SocketStreamTest::DoFailByTooBigDataAndClose, base::Unretained(this)));
+
+ TestURLRequestContext context;
+
+ scoped_refptr<SocketStream> socket_stream(
+ new SocketStream(GURL("ws://example.com/demo"), delegate.get()));
+
+ socket_stream->set_context(&context);
+
+ DelayedSocketData data_provider(1, NULL, 0, NULL, 0);
+
+ MockClientSocketFactory* mock_socket_factory =
+ GetMockClientSocketFactory();
+ mock_socket_factory->AddSocketDataProvider(&data_provider);
+
+ socket_stream->SetClientSocketFactory(mock_socket_factory);
+
+ socket_stream->Connect();
+
+ test_callback.WaitForResult();
+
+ const std::vector<SocketStreamEvent>& events = delegate->GetSeenEvents();
+ ASSERT_EQ(4U, events.size());
+
+ EXPECT_EQ(SocketStreamEvent::EVENT_START_OPEN_CONNECTION,
+ events[0].event_type);
+ EXPECT_EQ(SocketStreamEvent::EVENT_CONNECTED, events[1].event_type);
+ EXPECT_EQ(SocketStreamEvent::EVENT_ERROR, events[2].event_type);
+ EXPECT_EQ(SocketStreamEvent::EVENT_CLOSE, events[3].event_type);
+}
+
TEST_F(SocketStreamTest, BasicAuthProxy) {
MockClientSocketFactory mock_socket_factory;
MockWrite data_writes1[] = {