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

Unified Diff: content/browser/download/byte_stream_unittest.cc

Issue 10392111: Use ByteStream in downloads system to decouple source and sink. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Sync'd to LKGR. Created 8 years, 6 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/download/byte_stream.cc ('k') | content/browser/download/download_buffer.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/download/byte_stream_unittest.cc
diff --git a/content/browser/download/byte_stream_unittest.cc b/content/browser/download/byte_stream_unittest.cc
index 44bca9a8848a47b34b65f25e7354fef1b929274c..483641aea90ac1582f76ef49bd9bf220ace267a2 100644
--- a/content/browser/download/byte_stream_unittest.cc
+++ b/content/browser/download/byte_stream_unittest.cc
@@ -85,7 +85,7 @@ class ByteStreamTest : public testing::Test {
// ByteStream, returning the result of the ByteStream::Write.
// Separate function to avoid duplication of buffer_size in test
// calls.
- bool Write(content::ByteStreamInput* byte_stream_input,
+ bool Write(content::ByteStreamWriter* byte_stream_input,
size_t buffer_size) {
return byte_stream_input->Write(NewIOBuffer(buffer_size), buffer_size);
}
@@ -139,11 +139,11 @@ ByteStreamTest::ByteStreamTest()
: producing_seed_key_(0),
consuming_seed_key_(0) { }
-// Confirm that filling and emptying the pipe works properly, and that
+// Confirm that filling and emptying the stream works properly, and that
// we get full triggers when we expect.
TEST_F(ByteStreamTest, ByteStream_PushBack) {
- scoped_ptr<content::ByteStreamInput> byte_stream_input;
- scoped_ptr<content::ByteStreamOutput> byte_stream_output;
+ scoped_ptr<content::ByteStreamWriter> byte_stream_input;
+ scoped_ptr<content::ByteStreamReader> byte_stream_output;
content::CreateByteStream(
message_loop_.message_loop_proxy(), message_loop_.message_loop_proxy(),
3 * 1024, &byte_stream_input, &byte_stream_output);
@@ -163,27 +163,27 @@ TEST_F(ByteStreamTest, ByteStream_PushBack) {
// have the same contents?
scoped_refptr<net::IOBuffer> output_io_buffer;
size_t output_length;
- EXPECT_EQ(content::ByteStreamOutput::STREAM_HAS_DATA,
+ EXPECT_EQ(content::ByteStreamReader::STREAM_HAS_DATA,
byte_stream_output->Read(&output_io_buffer, &output_length));
EXPECT_TRUE(ValidateIOBuffer(output_io_buffer, output_length));
- EXPECT_EQ(content::ByteStreamOutput::STREAM_HAS_DATA,
+ EXPECT_EQ(content::ByteStreamReader::STREAM_HAS_DATA,
byte_stream_output->Read(&output_io_buffer, &output_length));
EXPECT_TRUE(ValidateIOBuffer(output_io_buffer, output_length));
- EXPECT_EQ(content::ByteStreamOutput::STREAM_HAS_DATA,
+ EXPECT_EQ(content::ByteStreamReader::STREAM_HAS_DATA,
byte_stream_output->Read(&output_io_buffer, &output_length));
EXPECT_TRUE(ValidateIOBuffer(output_io_buffer, output_length));
- EXPECT_EQ(content::ByteStreamOutput::STREAM_HAS_DATA,
+ EXPECT_EQ(content::ByteStreamReader::STREAM_HAS_DATA,
byte_stream_output->Read(&output_io_buffer, &output_length));
EXPECT_TRUE(ValidateIOBuffer(output_io_buffer, output_length));
- EXPECT_EQ(content::ByteStreamOutput::STREAM_HAS_DATA,
+ EXPECT_EQ(content::ByteStreamReader::STREAM_HAS_DATA,
byte_stream_output->Read(&output_io_buffer, &output_length));
EXPECT_TRUE(ValidateIOBuffer(output_io_buffer, output_length));
- EXPECT_EQ(content::ByteStreamOutput::STREAM_COMPLETE,
+ EXPECT_EQ(content::ByteStreamReader::STREAM_COMPLETE,
byte_stream_output->Read(&output_io_buffer, &output_length));
}
@@ -191,8 +191,8 @@ TEST_F(ByteStreamTest, ByteStream_PushBack) {
// that we're getting pushback even when data's split across the two
// objects
TEST_F(ByteStreamTest, ByteStream_PushBackSplit) {
- scoped_ptr<content::ByteStreamInput> byte_stream_input;
- scoped_ptr<content::ByteStreamOutput> byte_stream_output;
+ scoped_ptr<content::ByteStreamWriter> byte_stream_input;
+ scoped_ptr<content::ByteStreamReader> byte_stream_output;
content::CreateByteStream(
message_loop_.message_loop_proxy(), message_loop_.message_loop_proxy(),
9 * 1024, &byte_stream_input, &byte_stream_output);
@@ -214,35 +214,35 @@ TEST_F(ByteStreamTest, ByteStream_PushBackSplit) {
// have the same contents?
scoped_refptr<net::IOBuffer> output_io_buffer;
size_t output_length;
- EXPECT_EQ(content::ByteStreamOutput::STREAM_HAS_DATA,
+ EXPECT_EQ(content::ByteStreamReader::STREAM_HAS_DATA,
byte_stream_output->Read(&output_io_buffer, &output_length));
EXPECT_TRUE(ValidateIOBuffer(output_io_buffer, output_length));
- EXPECT_EQ(content::ByteStreamOutput::STREAM_HAS_DATA,
+ EXPECT_EQ(content::ByteStreamReader::STREAM_HAS_DATA,
byte_stream_output->Read(&output_io_buffer, &output_length));
EXPECT_TRUE(ValidateIOBuffer(output_io_buffer, output_length));
- EXPECT_EQ(content::ByteStreamOutput::STREAM_HAS_DATA,
+ EXPECT_EQ(content::ByteStreamReader::STREAM_HAS_DATA,
byte_stream_output->Read(&output_io_buffer, &output_length));
EXPECT_TRUE(ValidateIOBuffer(output_io_buffer, output_length));
- EXPECT_EQ(content::ByteStreamOutput::STREAM_HAS_DATA,
+ EXPECT_EQ(content::ByteStreamReader::STREAM_HAS_DATA,
byte_stream_output->Read(&output_io_buffer, &output_length));
EXPECT_TRUE(ValidateIOBuffer(output_io_buffer, output_length));
- EXPECT_EQ(content::ByteStreamOutput::STREAM_HAS_DATA,
+ EXPECT_EQ(content::ByteStreamReader::STREAM_HAS_DATA,
byte_stream_output->Read(&output_io_buffer, &output_length));
EXPECT_TRUE(ValidateIOBuffer(output_io_buffer, output_length));
- EXPECT_EQ(content::ByteStreamOutput::STREAM_EMPTY,
+ EXPECT_EQ(content::ByteStreamReader::STREAM_EMPTY,
byte_stream_output->Read(&output_io_buffer, &output_length));
}
// Confirm that a Close() notification transmits in-order
-// with data on the pipe.
+// with data on the stream.
TEST_F(ByteStreamTest, ByteStream_CompleteTransmits) {
- scoped_ptr<content::ByteStreamInput> byte_stream_input;
- scoped_ptr<content::ByteStreamOutput> byte_stream_output;
+ scoped_ptr<content::ByteStreamWriter> byte_stream_input;
+ scoped_ptr<content::ByteStreamReader> byte_stream_output;
scoped_refptr<net::IOBuffer> output_io_buffer;
size_t output_length;
@@ -251,11 +251,11 @@ TEST_F(ByteStreamTest, ByteStream_CompleteTransmits) {
content::CreateByteStream(
message_loop_.message_loop_proxy(), message_loop_.message_loop_proxy(),
3 * 1024, &byte_stream_input, &byte_stream_output);
- EXPECT_EQ(content::ByteStreamOutput::STREAM_EMPTY,
+ EXPECT_EQ(content::ByteStreamReader::STREAM_EMPTY,
byte_stream_output->Read(&output_io_buffer, &output_length));
byte_stream_input->Close(content::DOWNLOAD_INTERRUPT_REASON_NONE);
message_loop_.RunAllPending();
- ASSERT_EQ(content::ByteStreamOutput::STREAM_COMPLETE,
+ ASSERT_EQ(content::ByteStreamReader::STREAM_COMPLETE,
byte_stream_output->Read(&output_io_buffer, &output_length));
EXPECT_EQ(content::DOWNLOAD_INTERRUPT_REASON_NONE,
byte_stream_output->GetStatus());
@@ -264,15 +264,15 @@ TEST_F(ByteStreamTest, ByteStream_CompleteTransmits) {
content::CreateByteStream(
message_loop_.message_loop_proxy(), message_loop_.message_loop_proxy(),
3 * 1024, &byte_stream_input, &byte_stream_output);
- EXPECT_EQ(content::ByteStreamOutput::STREAM_EMPTY,
+ EXPECT_EQ(content::ByteStreamReader::STREAM_EMPTY,
byte_stream_output->Read(&output_io_buffer, &output_length));
EXPECT_TRUE(Write(byte_stream_input.get(), 1024));
byte_stream_input->Close(content::DOWNLOAD_INTERRUPT_REASON_NONE);
message_loop_.RunAllPending();
- EXPECT_EQ(content::ByteStreamOutput::STREAM_HAS_DATA,
+ EXPECT_EQ(content::ByteStreamReader::STREAM_HAS_DATA,
byte_stream_output->Read(&output_io_buffer, &output_length));
EXPECT_TRUE(ValidateIOBuffer(output_io_buffer, output_length));
- ASSERT_EQ(content::ByteStreamOutput::STREAM_COMPLETE,
+ ASSERT_EQ(content::ByteStreamReader::STREAM_COMPLETE,
byte_stream_output->Read(&output_io_buffer, &output_length));
EXPECT_EQ(content::DOWNLOAD_INTERRUPT_REASON_NONE,
byte_stream_output->GetStatus());
@@ -281,12 +281,12 @@ TEST_F(ByteStreamTest, ByteStream_CompleteTransmits) {
content::CreateByteStream(
message_loop_.message_loop_proxy(), message_loop_.message_loop_proxy(),
3 * 1024, &byte_stream_input, &byte_stream_output);
- EXPECT_EQ(content::ByteStreamOutput::STREAM_EMPTY,
+ EXPECT_EQ(content::ByteStreamReader::STREAM_EMPTY,
byte_stream_output->Read(&output_io_buffer, &output_length));
byte_stream_input->Close(
content::DOWNLOAD_INTERRUPT_REASON_NETWORK_DISCONNECTED);
message_loop_.RunAllPending();
- ASSERT_EQ(content::ByteStreamOutput::STREAM_COMPLETE,
+ ASSERT_EQ(content::ByteStreamReader::STREAM_COMPLETE,
byte_stream_output->Read(&output_io_buffer, &output_length));
EXPECT_EQ(content::DOWNLOAD_INTERRUPT_REASON_NETWORK_DISCONNECTED,
byte_stream_output->GetStatus());
@@ -295,16 +295,16 @@ TEST_F(ByteStreamTest, ByteStream_CompleteTransmits) {
content::CreateByteStream(
message_loop_.message_loop_proxy(), message_loop_.message_loop_proxy(),
3 * 1024, &byte_stream_input, &byte_stream_output);
- EXPECT_EQ(content::ByteStreamOutput::STREAM_EMPTY,
+ EXPECT_EQ(content::ByteStreamReader::STREAM_EMPTY,
byte_stream_output->Read(&output_io_buffer, &output_length));
EXPECT_TRUE(Write(byte_stream_input.get(), 1024));
byte_stream_input->Close(
content::DOWNLOAD_INTERRUPT_REASON_NETWORK_DISCONNECTED);
message_loop_.RunAllPending();
- EXPECT_EQ(content::ByteStreamOutput::STREAM_HAS_DATA,
+ EXPECT_EQ(content::ByteStreamReader::STREAM_HAS_DATA,
byte_stream_output->Read(&output_io_buffer, &output_length));
EXPECT_TRUE(ValidateIOBuffer(output_io_buffer, output_length));
- ASSERT_EQ(content::ByteStreamOutput::STREAM_COMPLETE,
+ ASSERT_EQ(content::ByteStreamReader::STREAM_COMPLETE,
byte_stream_output->Read(&output_io_buffer, &output_length));
EXPECT_EQ(content::DOWNLOAD_INTERRUPT_REASON_NETWORK_DISCONNECTED,
byte_stream_output->GetStatus());
@@ -316,8 +316,8 @@ TEST_F(ByteStreamTest, ByteStream_SinkCallback) {
EXPECT_CALL(*task_runner.get(), RunsTasksOnCurrentThread())
.WillRepeatedly(Return(true));
- scoped_ptr<content::ByteStreamInput> byte_stream_input;
- scoped_ptr<content::ByteStreamOutput> byte_stream_output;
+ scoped_ptr<content::ByteStreamWriter> byte_stream_input;
+ scoped_ptr<content::ByteStreamReader> byte_stream_output;
content::CreateByteStream(
message_loop_.message_loop_proxy(), task_runner,
10000, &byte_stream_input, &byte_stream_output);
@@ -327,7 +327,7 @@ TEST_F(ByteStreamTest, ByteStream_SinkCallback) {
base::Closure intermediate_callback;
// Note that the specifics of when the callbacks are called with regard
- // to how much data is pushed onto the pipe is not (currently) part
+ // to how much data is pushed onto the stream is not (currently) part
// of the interface contract. If it becomes part of the contract, the
// tests below should get much more precise.
@@ -353,10 +353,10 @@ TEST_F(ByteStreamTest, ByteStream_SinkCallback) {
EXPECT_EQ(1, num_callbacks);
// Check data and stream state.
- EXPECT_EQ(content::ByteStreamOutput::STREAM_HAS_DATA,
+ EXPECT_EQ(content::ByteStreamReader::STREAM_HAS_DATA,
byte_stream_output->Read(&output_io_buffer, &output_length));
EXPECT_TRUE(ValidateIOBuffer(output_io_buffer, output_length));
- EXPECT_EQ(content::ByteStreamOutput::STREAM_EMPTY,
+ EXPECT_EQ(content::ByteStreamReader::STREAM_EMPTY,
byte_stream_output->Read(&output_io_buffer, &output_length));
// Confirm callback *isn't* called at less than 33% (by lack of
@@ -366,7 +366,7 @@ TEST_F(ByteStreamTest, ByteStream_SinkCallback) {
// This reflects an implementation artifact that data goes with callbacks,
// which should not be considered part of the interface guarantee.
- EXPECT_EQ(content::ByteStreamOutput::STREAM_EMPTY,
+ EXPECT_EQ(content::ByteStreamReader::STREAM_EMPTY,
byte_stream_output->Read(&output_io_buffer, &output_length));
}
@@ -377,8 +377,8 @@ TEST_F(ByteStreamTest, ByteStream_SourceCallback) {
EXPECT_CALL(*task_runner.get(), RunsTasksOnCurrentThread())
.WillRepeatedly(Return(true));
- scoped_ptr<content::ByteStreamInput> byte_stream_input;
- scoped_ptr<content::ByteStreamOutput> byte_stream_output;
+ scoped_ptr<content::ByteStreamWriter> byte_stream_input;
+ scoped_ptr<content::ByteStreamReader> byte_stream_output;
content::CreateByteStream(
task_runner, message_loop_.message_loop_proxy(),
10000, &byte_stream_input, &byte_stream_output);
@@ -388,7 +388,7 @@ TEST_F(ByteStreamTest, ByteStream_SourceCallback) {
base::Closure intermediate_callback;
// Note that the specifics of when the callbacks are called with regard
- // to how much data is pulled from the pipe is not (currently) part
+ // to how much data is pulled from the stream is not (currently) part
// of the interface contract. If it becomes part of the contract, the
// tests below should get much more precise.
@@ -406,7 +406,7 @@ TEST_F(ByteStreamTest, ByteStream_SourceCallback) {
// Allow bytes to transition (needed for message passing implementation),
// and get and validate the data.
message_loop_.RunAllPending();
- EXPECT_EQ(content::ByteStreamOutput::STREAM_HAS_DATA,
+ EXPECT_EQ(content::ByteStreamReader::STREAM_HAS_DATA,
byte_stream_output->Read(&output_io_buffer, &output_length));
EXPECT_TRUE(ValidateIOBuffer(output_io_buffer, output_length));
@@ -417,7 +417,7 @@ TEST_F(ByteStreamTest, ByteStream_SourceCallback) {
// Grab data, triggering callback. Recorded on dispatch, but doesn't
// happen because it's caught by the mock.
- EXPECT_EQ(content::ByteStreamOutput::STREAM_HAS_DATA,
+ EXPECT_EQ(content::ByteStreamReader::STREAM_HAS_DATA,
byte_stream_output->Read(&output_io_buffer, &output_length));
::testing::Mock::VerifyAndClearExpectations(task_runner.get());
EXPECT_CALL(*task_runner.get(), RunsTasksOnCurrentThread())
@@ -433,13 +433,13 @@ TEST_F(ByteStreamTest, ByteStream_SourceCallback) {
EXPECT_CALL(*task_runner.get(), PostDelayedTask(_, _, 0))
.WillOnce(DoAll(SaveArg<1>(&intermediate_callback),
Return(true)));
- EXPECT_EQ(content::ByteStreamOutput::STREAM_HAS_DATA,
+ EXPECT_EQ(content::ByteStreamReader::STREAM_HAS_DATA,
byte_stream_output->Read(&output_io_buffer, &output_length));
::testing::Mock::VerifyAndClearExpectations(task_runner.get());
EXPECT_CALL(*task_runner.get(), RunsTasksOnCurrentThread())
.WillRepeatedly(Return(true));
EXPECT_TRUE(ValidateIOBuffer(output_io_buffer, output_length));
- EXPECT_EQ(content::ByteStreamOutput::STREAM_EMPTY,
+ EXPECT_EQ(content::ByteStreamReader::STREAM_EMPTY,
byte_stream_output->Read(&output_io_buffer, &output_length));
EXPECT_EQ(1, num_callbacks);
intermediate_callback.Run();
@@ -455,8 +455,8 @@ TEST_F(ByteStreamTest, ByteStream_SinkInterrupt) {
EXPECT_CALL(*task_runner.get(), RunsTasksOnCurrentThread())
.WillRepeatedly(Return(true));
- scoped_ptr<content::ByteStreamInput> byte_stream_input;
- scoped_ptr<content::ByteStreamOutput> byte_stream_output;
+ scoped_ptr<content::ByteStreamWriter> byte_stream_input;
+ scoped_ptr<content::ByteStreamReader> byte_stream_output;
content::CreateByteStream(
message_loop_.message_loop_proxy(), task_runner,
10000, &byte_stream_input, &byte_stream_output);
@@ -494,10 +494,10 @@ TEST_F(ByteStreamTest, ByteStream_SinkInterrupt) {
EXPECT_EQ(1, num_alt_callbacks);
// Final cleanup.
- EXPECT_EQ(content::ByteStreamOutput::STREAM_HAS_DATA,
+ EXPECT_EQ(content::ByteStreamReader::STREAM_HAS_DATA,
byte_stream_output->Read(&output_io_buffer, &output_length));
EXPECT_TRUE(ValidateIOBuffer(output_io_buffer, output_length));
- EXPECT_EQ(content::ByteStreamOutput::STREAM_EMPTY,
+ EXPECT_EQ(content::ByteStreamReader::STREAM_EMPTY,
byte_stream_output->Read(&output_io_buffer, &output_length));
}
@@ -509,8 +509,8 @@ TEST_F(ByteStreamTest, ByteStream_SourceInterrupt) {
EXPECT_CALL(*task_runner.get(), RunsTasksOnCurrentThread())
.WillRepeatedly(Return(true));
- scoped_ptr<content::ByteStreamInput> byte_stream_input;
- scoped_ptr<content::ByteStreamOutput> byte_stream_output;
+ scoped_ptr<content::ByteStreamWriter> byte_stream_input;
+ scoped_ptr<content::ByteStreamReader> byte_stream_output;
content::CreateByteStream(
task_runner, message_loop_.message_loop_proxy(),
10000, &byte_stream_input, &byte_stream_output);
@@ -529,7 +529,7 @@ TEST_F(ByteStreamTest, ByteStream_SourceInterrupt) {
message_loop_.RunAllPending();
// Initial get should not trigger callback.
- EXPECT_EQ(content::ByteStreamOutput::STREAM_HAS_DATA,
+ EXPECT_EQ(content::ByteStreamReader::STREAM_HAS_DATA,
byte_stream_output->Read(&output_io_buffer, &output_length));
EXPECT_TRUE(ValidateIOBuffer(output_io_buffer, output_length));
message_loop_.RunAllPending();
@@ -540,7 +540,7 @@ TEST_F(ByteStreamTest, ByteStream_SourceInterrupt) {
Return(true)));
// Second get *should* trigger callback.
- EXPECT_EQ(content::ByteStreamOutput::STREAM_HAS_DATA,
+ EXPECT_EQ(content::ByteStreamReader::STREAM_HAS_DATA,
byte_stream_output->Read(&output_io_buffer, &output_length));
::testing::Mock::VerifyAndClearExpectations(task_runner.get());
EXPECT_CALL(*task_runner.get(), RunsTasksOnCurrentThread())
@@ -559,13 +559,13 @@ TEST_F(ByteStreamTest, ByteStream_SourceInterrupt) {
EXPECT_CALL(*task_runner.get(), PostDelayedTask(_, _, 0))
.WillOnce(DoAll(SaveArg<1>(&intermediate_callback),
Return(true)));
- EXPECT_EQ(content::ByteStreamOutput::STREAM_HAS_DATA,
+ EXPECT_EQ(content::ByteStreamReader::STREAM_HAS_DATA,
byte_stream_output->Read(&output_io_buffer, &output_length));
::testing::Mock::VerifyAndClearExpectations(task_runner.get());
EXPECT_CALL(*task_runner.get(), RunsTasksOnCurrentThread())
.WillRepeatedly(Return(true));
EXPECT_TRUE(ValidateIOBuffer(output_io_buffer, output_length));
- EXPECT_EQ(content::ByteStreamOutput::STREAM_EMPTY,
+ EXPECT_EQ(content::ByteStreamReader::STREAM_EMPTY,
byte_stream_output->Read(&output_io_buffer, &output_length));
}
@@ -576,8 +576,8 @@ TEST_F(ByteStreamTest, ByteStream_ZeroCallback) {
EXPECT_CALL(*task_runner.get(), RunsTasksOnCurrentThread())
.WillRepeatedly(Return(true));
- scoped_ptr<content::ByteStreamInput> byte_stream_input;
- scoped_ptr<content::ByteStreamOutput> byte_stream_output;
+ scoped_ptr<content::ByteStreamWriter> byte_stream_input;
+ scoped_ptr<content::ByteStreamReader> byte_stream_output;
content::CreateByteStream(
message_loop_.message_loop_proxy(), task_runner,
10000, &byte_stream_input, &byte_stream_output);
« no previous file with comments | « content/browser/download/byte_stream.cc ('k') | content/browser/download/download_buffer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698