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

Unified Diff: content/child/shared_memory_data_consumer_handle_unittest.cc

Issue 1186053004: Cancel loading when body stream reader is detached. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@error-ipc-data-consumer
Patch Set: Created 5 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/child/shared_memory_data_consumer_handle.cc ('k') | content/child/web_url_loader_impl.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/child/shared_memory_data_consumer_handle_unittest.cc
diff --git a/content/child/shared_memory_data_consumer_handle_unittest.cc b/content/child/shared_memory_data_consumer_handle_unittest.cc
index f590106d545b8c7ed23d2c9a72d3dc8fe5013d04..87136639c524dab638fa3913766b7ddb6d24e716 100644
--- a/content/child/shared_memory_data_consumer_handle_unittest.cc
+++ b/content/child/shared_memory_data_consumer_handle_unittest.cc
@@ -85,6 +85,17 @@ class LoggingFixedReceivedData final : public RequestPeer::ReceivedData {
DISALLOW_COPY_AND_ASSIGN(LoggingFixedReceivedData);
};
+class DestructionTrackingFunction
+ : public base::RefCountedThreadSafe<DestructionTrackingFunction> {
+ public:
+ MOCK_METHOD0(Destruct, void(void));
+ MOCK_METHOD0(Call, void(void));
+
+ protected:
+ friend class base::RefCountedThreadSafe<DestructionTrackingFunction>;
+ virtual ~DestructionTrackingFunction() { Destruct(); }
+};
+
class MockClient : public WebDataConsumerHandle::Client {
public:
MOCK_METHOD0(didGetReadable, void());
@@ -582,6 +593,115 @@ TEST_P(SharedMemoryDataConsumerHandleTest, TwoPhaseReadSimple) {
EXPECT_EQ(nullptr, buffer);
}
+TEST_P(SharedMemoryDataConsumerHandleTest, CallOnClearWhenDestructed1) {
+ // Call |on_clear| when the handle is gone and if there is no reader.
+ Checkpoint checkpoint;
+ scoped_refptr<DestructionTrackingFunction> on_clear(
+ new StrictMock<DestructionTrackingFunction>);
+
+ InSequence s;
+ EXPECT_CALL(checkpoint, Call(0));
+ EXPECT_CALL(checkpoint, Call(1));
+ EXPECT_CALL(*on_clear, Call());
+ EXPECT_CALL(*on_clear, Destruct());
+ EXPECT_CALL(checkpoint, Call(2));
+
+ checkpoint.Call(0);
+ handle_.reset(new SharedMemoryDataConsumerHandle(
+ kApplyBackpressure,
+ base::Bind(&DestructionTrackingFunction::Call, on_clear), &writer_));
+ handle_.reset();
+ on_clear = nullptr;
+ checkpoint.Call(1);
+ RunPostedTasks();
+ checkpoint.Call(2);
+}
+
+TEST_P(SharedMemoryDataConsumerHandleTest, CallOnClearWhenDestructed2) {
+ // Call |on_clear| when the reader is gone if the handle is alredy gone.
+ Checkpoint checkpoint;
+ scoped_refptr<DestructionTrackingFunction> on_clear(
+ new StrictMock<DestructionTrackingFunction>);
+
+ InSequence s;
+ EXPECT_CALL(checkpoint, Call(0));
+ EXPECT_CALL(checkpoint, Call(1));
+ EXPECT_CALL(checkpoint, Call(2));
+ EXPECT_CALL(checkpoint, Call(3));
+ EXPECT_CALL(*on_clear, Call());
+ EXPECT_CALL(*on_clear, Destruct());
+ EXPECT_CALL(checkpoint, Call(4));
+
+ checkpoint.Call(0);
+ handle_.reset(new SharedMemoryDataConsumerHandle(
+ kApplyBackpressure,
+ base::Bind(&DestructionTrackingFunction::Call, on_clear), &writer_));
+ auto reader = handle_->ObtainReader(nullptr);
+ handle_.reset();
+ on_clear = nullptr;
+ checkpoint.Call(1);
+ RunPostedTasks();
+ checkpoint.Call(2);
+ reader.reset();
+ checkpoint.Call(3);
+ RunPostedTasks();
+ checkpoint.Call(4);
+}
+
+TEST_P(SharedMemoryDataConsumerHandleTest, DoNotCallOnClearWhenDone) {
+ Checkpoint checkpoint;
+ scoped_refptr<DestructionTrackingFunction> on_clear(
+ new StrictMock<DestructionTrackingFunction>);
+
+ InSequence s;
+ EXPECT_CALL(checkpoint, Call(0));
+ EXPECT_CALL(checkpoint, Call(1));
+ EXPECT_CALL(*on_clear, Destruct());
+ EXPECT_CALL(checkpoint, Call(2));
+ EXPECT_CALL(checkpoint, Call(3));
+ EXPECT_CALL(checkpoint, Call(4));
+
+ checkpoint.Call(0);
+ handle_.reset(new SharedMemoryDataConsumerHandle(
+ kApplyBackpressure,
+ base::Bind(&DestructionTrackingFunction::Call, on_clear), &writer_));
+ on_clear = nullptr;
+ checkpoint.Call(1);
+ writer_->Close();
+ checkpoint.Call(2);
+ handle_.reset();
+ checkpoint.Call(3);
+ RunPostedTasks();
+ checkpoint.Call(4);
+}
+
+TEST_P(SharedMemoryDataConsumerHandleTest, DoNotCallOnClearWhenErrored) {
+ Checkpoint checkpoint;
+ scoped_refptr<DestructionTrackingFunction> on_clear(
+ new StrictMock<DestructionTrackingFunction>);
+
+ InSequence s;
+ EXPECT_CALL(checkpoint, Call(0));
+ EXPECT_CALL(checkpoint, Call(1));
+ EXPECT_CALL(*on_clear, Destruct());
+ EXPECT_CALL(checkpoint, Call(2));
+ EXPECT_CALL(checkpoint, Call(3));
+ EXPECT_CALL(checkpoint, Call(4));
+
+ checkpoint.Call(0);
+ handle_.reset(new SharedMemoryDataConsumerHandle(
+ kApplyBackpressure,
+ base::Bind(&DestructionTrackingFunction::Call, on_clear), &writer_));
+ on_clear = nullptr;
+ checkpoint.Call(1);
+ writer_->Fail();
+ checkpoint.Call(2);
+ handle_.reset();
+ checkpoint.Call(3);
+ RunPostedTasks();
+ checkpoint.Call(4);
+}
+
TEST_P(SharedMemoryDataConsumerHandleTest, TwoPhaseReadWithMultipleData) {
writer_->AddData(NewFixedData("Once "));
writer_->AddData(NewFixedData("upon "));
« no previous file with comments | « content/child/shared_memory_data_consumer_handle.cc ('k') | content/child/web_url_loader_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698