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

Unified Diff: content/browser/byte_stream_unittest.cc

Issue 22908008: Limit the total memory usage for Stream instances (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: creis's comments Created 7 years, 4 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
« no previous file with comments | « content/browser/byte_stream.cc ('k') | content/browser/fileapi/fileapi_message_filter.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/byte_stream_unittest.cc
diff --git a/content/browser/byte_stream_unittest.cc b/content/browser/byte_stream_unittest.cc
index 04c5ae3753306b721a80dd7575309955b3156001..f814e2f5d083f4bd9fc1563634cfca58df352bcd 100644
--- a/content/browser/byte_stream_unittest.cc
+++ b/content/browser/byte_stream_unittest.cc
@@ -5,6 +5,7 @@
#include "content/browser/byte_stream.h"
#include <deque>
+#include <limits>
#include "base/bind.h"
#include "base/callback.h"
@@ -116,7 +117,10 @@ TEST_F(ByteStreamTest, ByteStream_PushBack) {
EXPECT_FALSE(Write(byte_stream_input.get(), 1024));
// Flush
byte_stream_input->Close(0);
+ EXPECT_EQ(4 * 1024U + 1U, byte_stream_input->GetTotalBufferedBytes());
message_loop_.RunUntilIdle();
+ // Data already sent to reader is also counted in.
+ EXPECT_EQ(4 * 1024U + 1U, byte_stream_input->GetTotalBufferedBytes());
// Pull the IO buffers out; do we get the same buffers and do they
// have the same contents?
@@ -144,6 +148,10 @@ TEST_F(ByteStreamTest, ByteStream_PushBack) {
EXPECT_EQ(ByteStreamReader::STREAM_COMPLETE,
byte_stream_output->Read(&output_io_buffer, &output_length));
+
+ message_loop_.RunUntilIdle();
+ // Reader now knows that all data is read out.
+ EXPECT_EQ(1024U, byte_stream_input->GetTotalBufferedBytes());
}
// Confirm that Flush() method makes the writer to send written contents to
@@ -579,4 +587,27 @@ TEST_F(ByteStreamTest, ByteStream_FlushWithoutAnyWrite) {
byte_stream_output->Read(&output_io_buffer, &output_length));
}
+TEST_F(ByteStreamTest, ByteStream_WriteOverflow) {
+ scoped_ptr<ByteStreamWriter> byte_stream_input;
+ scoped_ptr<ByteStreamReader> byte_stream_output;
+ CreateByteStream(
+ message_loop_.message_loop_proxy(), message_loop_.message_loop_proxy(),
+ std::numeric_limits<size_t>::max(),
+ &byte_stream_input, &byte_stream_output);
+
+ EXPECT_TRUE(Write(byte_stream_input.get(), 1));
+ // 1 + size_t max -> Overflow.
+ scoped_refptr<net::IOBuffer> empty_io_buffer;
+ EXPECT_FALSE(byte_stream_input->Write(empty_io_buffer,
+ std::numeric_limits<size_t>::max()));
+ message_loop_.RunUntilIdle();
+
+ // The first write is below PostToPeer threshold. We shouldn't get anything
+ // from the output.
+ scoped_refptr<net::IOBuffer> output_io_buffer;
+ size_t output_length;
+ EXPECT_EQ(ByteStreamReader::STREAM_EMPTY,
+ byte_stream_output->Read(&output_io_buffer, &output_length));
+}
+
} // namespace content
« no previous file with comments | « content/browser/byte_stream.cc ('k') | content/browser/fileapi/fileapi_message_filter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698