Index: content/child/web_data_consumer_handle_impl_unittest.cc |
diff --git a/content/child/web_data_consumer_handle_impl_unittest.cc b/content/child/web_data_consumer_handle_impl_unittest.cc |
index 46a5de9ce211877efb936610f52d885b9691cdb2..de636042c7f6c6b819365de5fa22f02210b7374c 100644 |
--- a/content/child/web_data_consumer_handle_impl_unittest.cc |
+++ b/content/child/web_data_consumer_handle_impl_unittest.cc |
@@ -193,12 +193,14 @@ class WebDataConsumerHandleImplTest : public ::testing::Test { |
options.struct_size = sizeof(MojoCreateDataPipeOptions); |
options.flags = MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE; |
options.element_num_bytes = 1; |
- options.capacity_num_bytes = 4; |
+ options.capacity_num_bytes = kDataPipeCapacity; |
MojoResult result = mojo::CreateDataPipe(&options, &producer_, &consumer_); |
ASSERT_EQ(MOJO_RESULT_OK, result); |
} |
+ protected: |
+ static int kDataPipeCapacity; |
yhirano
2016/09/23 06:55:55
+ constexpr
horo
2016/09/23 07:38:37
Done.
|
// This function can be blocked if the associated consumer doesn't consume |
// the data. |
std::string ProduceData(size_t total_size) { |
@@ -234,6 +236,8 @@ class WebDataConsumerHandleImplTest : public ::testing::Test { |
mojo::ScopedDataPipeConsumerHandle consumer_; |
}; |
+int WebDataConsumerHandleImplTest::kDataPipeCapacity = 4; |
+ |
TEST_F(WebDataConsumerHandleImplTest, ReadData) { |
base::RunLoop run_loop; |
auto operation = base::MakeUnique<ReadDataOperation>( |
@@ -276,6 +280,29 @@ TEST_F(WebDataConsumerHandleImplTest, TwoPhaseReadData) { |
EXPECT_EQ(expected, operation->result()); |
} |
+TEST_F(WebDataConsumerHandleImplTest, ZeroSizeRead) { |
+ ASSERT_GT(kDataPipeCapacity - 1, 0); |
+ const size_t data_size = kDataPipeCapacity - 1; |
yhirano
2016/09/23 06:55:55
constexpr
horo
2016/09/23 07:38:37
Done.
|
+ std::string expected = ProduceData(data_size); |
+ producer_.reset(); |
+ std::unique_ptr<WebDataConsumerHandleImpl> handle( |
+ new WebDataConsumerHandleImpl(std::move(consumer_))); |
+ std::unique_ptr<WebDataConsumerHandle::Reader> reader( |
+ handle->obtainReader(nullptr)); |
+ |
+ size_t read_size; |
+ WebDataConsumerHandle::Result rv = |
+ reader->read(nullptr, 0, WebDataConsumerHandle::FlagNone, &read_size); |
+ EXPECT_EQ(WebDataConsumerHandle::Result::Ok, rv); |
+ |
+ char buffer[16]; |
+ rv = reader->read(&buffer, sizeof(buffer), WebDataConsumerHandle::FlagNone, |
+ &read_size); |
+ EXPECT_EQ(WebDataConsumerHandle::Result::Ok, rv); |
+ EXPECT_EQ(data_size, read_size); |
+ EXPECT_EQ(expected, std::string(buffer, read_size)); |
+} |
+ |
} // namespace |
} // namespace content |