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

Unified Diff: third_party/WebKit/Source/modules/fetch/BodyStreamBufferTest.cpp

Issue 1376153002: Clear BodyStreamBuffer::m_handle in close()/error() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add unit tests. Created 5 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 | « third_party/WebKit/Source/modules/fetch/BodyStreamBuffer.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/modules/fetch/BodyStreamBufferTest.cpp
diff --git a/third_party/WebKit/Source/modules/fetch/BodyStreamBufferTest.cpp b/third_party/WebKit/Source/modules/fetch/BodyStreamBufferTest.cpp
index 37bc9934dcae6ad8c2a1ac8db5c0731a631c46f4..769fc35bd6edb91f511a79dd37a88c618123d164 100644
--- a/third_party/WebKit/Source/modules/fetch/BodyStreamBufferTest.cpp
+++ b/third_party/WebKit/Source/modules/fetch/BodyStreamBufferTest.cpp
@@ -34,6 +34,7 @@ public:
~BodyStreamBufferTest() override {}
protected:
+ ScriptState* scriptState() { return ScriptState::forMainWorld(m_page->document().frame()); }
ExecutionContext* executionContext() { return &m_page->document(); }
OwnPtr<DummyPageHolder> m_page;
@@ -264,6 +265,46 @@ TEST_F(BodyStreamBufferTest, LoaderShouldBeKeptAliveByBodyStreamBuffer)
checkpoint.Call(2);
}
+// TODO(hiroshige): Merge this class into MockFetchDataConsumerHandle.
+class MockFetchDataConsumerHandleWithMockDestructor : public DataConsumerHandleTestUtil::MockFetchDataConsumerHandle {
+public:
+ static PassOwnPtr<::testing::StrictMock<MockFetchDataConsumerHandleWithMockDestructor>> create() { return adoptPtr(new ::testing::StrictMock<MockFetchDataConsumerHandleWithMockDestructor>); }
+
+ ~MockFetchDataConsumerHandleWithMockDestructor() override
+ {
+ destruct();
+ }
+
+ MOCK_METHOD0(destruct, void());
+};
+
+TEST_F(BodyStreamBufferTest, SourceHandleAndReaderShouldBeDestructedWhenCanceled)
+{
+ ScriptState::Scope scope(scriptState());
+ using MockHandle = MockFetchDataConsumerHandleWithMockDestructor;
+ using MockReader = DataConsumerHandleTestUtil::MockFetchDataConsumerReader;
+ OwnPtr<MockHandle> handle = MockHandle::create();
+ OwnPtr<MockReader> reader = MockReader::create();
+
+ Checkpoint checkpoint;
+ InSequence s;
+
+ EXPECT_CALL(*handle, obtainReaderInternal(_)).WillOnce(::testing::Return(reader.get()));
+ EXPECT_CALL(checkpoint, Call(1));
+ EXPECT_CALL(*reader, destruct());
+ EXPECT_CALL(*handle, destruct());
+ EXPECT_CALL(checkpoint, Call(2));
+
+ // |reader| is adopted by |obtainReader|.
+ ASSERT_TRUE(reader.leakPtr());
+
+ BodyStreamBuffer* buffer = new BodyStreamBuffer(handle.release());
+ checkpoint.Call(1);
+ ScriptValue reason(scriptState(), v8String(scriptState()->isolate(), "reason"));
+ buffer->cancelSource(scriptState(), reason);
+ checkpoint.Call(2);
+}
+
} // namespace
} // namespace blink
« no previous file with comments | « third_party/WebKit/Source/modules/fetch/BodyStreamBuffer.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698