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

Side by Side 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, 2 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 unified diff | Download patch
« no previous file with comments | « third_party/WebKit/Source/modules/fetch/BodyStreamBuffer.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "config.h" 5 #include "config.h"
6 #include "modules/fetch/BodyStreamBuffer.h" 6 #include "modules/fetch/BodyStreamBuffer.h"
7 7
8 #include "core/testing/DummyPageHolder.h" 8 #include "core/testing/DummyPageHolder.h"
9 #include "modules/fetch/DataConsumerHandleTestUtil.h" 9 #include "modules/fetch/DataConsumerHandleTestUtil.h"
10 #include "platform/testing/UnitTestHelpers.h" 10 #include "platform/testing/UnitTestHelpers.h"
(...skipping 16 matching lines...) Expand all
27 27
28 class BodyStreamBufferTest : public ::testing::Test { 28 class BodyStreamBufferTest : public ::testing::Test {
29 public: 29 public:
30 BodyStreamBufferTest() 30 BodyStreamBufferTest()
31 { 31 {
32 m_page = DummyPageHolder::create(IntSize(1, 1)); 32 m_page = DummyPageHolder::create(IntSize(1, 1));
33 } 33 }
34 ~BodyStreamBufferTest() override {} 34 ~BodyStreamBufferTest() override {}
35 35
36 protected: 36 protected:
37 ScriptState* scriptState() { return ScriptState::forMainWorld(m_page->docume nt().frame()); }
37 ExecutionContext* executionContext() { return &m_page->document(); } 38 ExecutionContext* executionContext() { return &m_page->document(); }
38 39
39 OwnPtr<DummyPageHolder> m_page; 40 OwnPtr<DummyPageHolder> m_page;
40 }; 41 };
41 42
42 TEST_F(BodyStreamBufferTest, LockBodyStreamBuffer) 43 TEST_F(BodyStreamBufferTest, LockBodyStreamBuffer)
43 { 44 {
44 OwnPtr<FetchDataConsumerHandle> handle = createFetchDataConsumerHandleFromWe bHandle(createWaitingDataConsumerHandle()); 45 OwnPtr<FetchDataConsumerHandle> handle = createFetchDataConsumerHandleFromWe bHandle(createWaitingDataConsumerHandle());
45 FetchDataConsumerHandle* rawHandle = handle.get(); 46 FetchDataConsumerHandle* rawHandle = handle.get();
46 BodyStreamBuffer* buffer = new BodyStreamBuffer(handle.release()); 47 BodyStreamBuffer* buffer = new BodyStreamBuffer(handle.release());
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 handle->add(Command(Command::Done)); 258 handle->add(Command(Command::Done));
258 Persistent<BodyStreamBuffer> buffer = new BodyStreamBuffer(createFetchDataCo nsumerHandleFromWebHandle(handle.release())); 259 Persistent<BodyStreamBuffer> buffer = new BodyStreamBuffer(createFetchDataCo nsumerHandleFromWebHandle(handle.release()));
259 buffer->startLoading(executionContext(), FetchDataLoader::createLoaderAsStri ng(), client); 260 buffer->startLoading(executionContext(), FetchDataLoader::createLoaderAsStri ng(), client);
260 261
261 Heap::collectAllGarbage(); 262 Heap::collectAllGarbage();
262 checkpoint.Call(1); 263 checkpoint.Call(1);
263 testing::runPendingTasks(); 264 testing::runPendingTasks();
264 checkpoint.Call(2); 265 checkpoint.Call(2);
265 } 266 }
266 267
268 // TODO(hiroshige): Merge this class into MockFetchDataConsumerHandle.
269 class MockFetchDataConsumerHandleWithMockDestructor : public DataConsumerHandleT estUtil::MockFetchDataConsumerHandle {
270 public:
271 static PassOwnPtr<::testing::StrictMock<MockFetchDataConsumerHandleWithMockD estructor>> create() { return adoptPtr(new ::testing::StrictMock<MockFetchDataCo nsumerHandleWithMockDestructor>); }
272
273 ~MockFetchDataConsumerHandleWithMockDestructor() override
274 {
275 destruct();
276 }
277
278 MOCK_METHOD0(destruct, void());
279 };
280
281 TEST_F(BodyStreamBufferTest, SourceHandleAndReaderShouldBeDestructedWhenCanceled )
282 {
283 ScriptState::Scope scope(scriptState());
284 using MockHandle = MockFetchDataConsumerHandleWithMockDestructor;
285 using MockReader = DataConsumerHandleTestUtil::MockFetchDataConsumerReader;
286 OwnPtr<MockHandle> handle = MockHandle::create();
287 OwnPtr<MockReader> reader = MockReader::create();
288
289 Checkpoint checkpoint;
290 InSequence s;
291
292 EXPECT_CALL(*handle, obtainReaderInternal(_)).WillOnce(::testing::Return(rea der.get()));
293 EXPECT_CALL(checkpoint, Call(1));
294 EXPECT_CALL(*reader, destruct());
295 EXPECT_CALL(*handle, destruct());
296 EXPECT_CALL(checkpoint, Call(2));
297
298 // |reader| is adopted by |obtainReader|.
299 ASSERT_TRUE(reader.leakPtr());
300
301 BodyStreamBuffer* buffer = new BodyStreamBuffer(handle.release());
302 checkpoint.Call(1);
303 ScriptValue reason(scriptState(), v8String(scriptState()->isolate(), "reason "));
304 buffer->cancelSource(scriptState(), reason);
305 checkpoint.Call(2);
306 }
307
267 } // namespace 308 } // namespace
268 309
269 } // namespace blink 310 } // namespace blink
OLDNEW
« 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