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

Unified Diff: content/child/web_data_consumer_handle_impl_unittest.cc

Issue 2363963002: Make WebDataConsumerHandleImpl return OK while zero-length reading of closed pipe. (Closed)
Patch Set: use mojo::Wait() with 0 deadline to check whether readable or not Created 4 years, 3 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/child/web_data_consumer_handle_impl.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..98e6c25171fd93c498301abb85c8f3b6eb46b725 100644
--- a/content/child/web_data_consumer_handle_impl_unittest.cc
+++ b/content/child/web_data_consumer_handle_impl_unittest.cc
@@ -193,12 +193,15 @@ 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 constexpr int kDataPipeCapacity = 4;
+
// This function can be blocked if the associated consumer doesn't consume
// the data.
std::string ProduceData(size_t total_size) {
@@ -276,6 +279,29 @@ TEST_F(WebDataConsumerHandleImplTest, TwoPhaseReadData) {
EXPECT_EQ(expected, operation->result());
}
+TEST_F(WebDataConsumerHandleImplTest, ZeroSizeRead) {
+ ASSERT_GT(kDataPipeCapacity - 1, 0);
+ constexpr size_t data_size = kDataPipeCapacity - 1;
+ 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
« no previous file with comments | « content/child/web_data_consumer_handle_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698