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

Side by Side Diff: third_party/WebKit/Source/modules/fetch/BodyStreamBufferTest.cpp

Issue 2172183003: Return unique_ptr<WebDataConsumerHandle::Reader> directly from obtainReader (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@gmock_cxx11
Patch Set: rebase Created 4 years, 4 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
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 "modules/fetch/BodyStreamBuffer.h" 5 #include "modules/fetch/BodyStreamBuffer.h"
6 6
7 #include "bindings/core/v8/V8BindingForTesting.h" 7 #include "bindings/core/v8/V8BindingForTesting.h"
8 #include "core/html/FormData.h" 8 #include "core/html/FormData.h"
9 #include "modules/fetch/DataConsumerHandleTestUtil.h" 9 #include "modules/fetch/DataConsumerHandleTestUtil.h"
10 #include "modules/fetch/FetchBlobDataConsumerHandle.h" 10 #include "modules/fetch/FetchBlobDataConsumerHandle.h"
11 #include "modules/fetch/FetchFormDataConsumerHandle.h" 11 #include "modules/fetch/FetchFormDataConsumerHandle.h"
12 #include "platform/blob/BlobData.h" 12 #include "platform/blob/BlobData.h"
13 #include "platform/blob/BlobURL.h" 13 #include "platform/blob/BlobURL.h"
14 #include "platform/network/EncodedFormData.h" 14 #include "platform/network/EncodedFormData.h"
15 #include "platform/testing/UnitTestHelpers.h" 15 #include "platform/testing/UnitTestHelpers.h"
16 #include "testing/gmock/include/gmock/gmock.h" 16 #include "testing/gmock/include/gmock/gmock.h"
17 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
18 #include "wtf/PtrUtil.h" 18 #include "wtf/PtrUtil.h"
19 #include <memory> 19 #include <memory>
20 20
21 namespace blink { 21 namespace blink {
22 22
23 namespace { 23 namespace {
24 24
25 using ::testing::ByMove;
25 using ::testing::InSequence; 26 using ::testing::InSequence;
27 using ::testing::Return;
26 using ::testing::_; 28 using ::testing::_;
27 using ::testing::SaveArg; 29 using ::testing::SaveArg;
28 using Checkpoint = ::testing::StrictMock<::testing::MockFunction<void(int)>>; 30 using Checkpoint = ::testing::StrictMock<::testing::MockFunction<void(int)>>;
29 using Command = DataConsumerHandleTestUtil::Command; 31 using Command = DataConsumerHandleTestUtil::Command;
30 using ReplayingHandle = DataConsumerHandleTestUtil::ReplayingHandle; 32 using ReplayingHandle = DataConsumerHandleTestUtil::ReplayingHandle;
31 using MockFetchDataLoaderClient = DataConsumerHandleTestUtil::MockFetchDataLoade rClient; 33 using MockFetchDataLoaderClient = DataConsumerHandleTestUtil::MockFetchDataLoade rClient;
32 34
33 class FakeLoaderFactory : public FetchBlobDataConsumerHandle::LoaderFactory { 35 class FakeLoaderFactory : public FetchBlobDataConsumerHandle::LoaderFactory {
34 public: 36 public:
35 std::unique_ptr<ThreadableLoader> create(ExecutionContext&, ThreadableLoader Client*, const ThreadableLoaderOptions&, const ResourceLoaderOptions&) override 37 std::unique_ptr<ThreadableLoader> create(ExecutionContext&, ThreadableLoader Client*, const ThreadableLoaderOptions&, const ResourceLoaderOptions&) override
(...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after
476 478
477 MOCK_METHOD0(destruct, void()); 479 MOCK_METHOD0(destruct, void());
478 }; 480 };
479 481
480 TEST_F(BodyStreamBufferTest, SourceHandleAndReaderShouldBeDestructedWhenCanceled ) 482 TEST_F(BodyStreamBufferTest, SourceHandleAndReaderShouldBeDestructedWhenCanceled )
481 { 483 {
482 V8TestingScope scope; 484 V8TestingScope scope;
483 using MockHandle = MockFetchDataConsumerHandleWithMockDestructor; 485 using MockHandle = MockFetchDataConsumerHandleWithMockDestructor;
484 using MockReader = DataConsumerHandleTestUtil::MockFetchDataConsumerReader; 486 using MockReader = DataConsumerHandleTestUtil::MockFetchDataConsumerReader;
485 std::unique_ptr<MockHandle> handle = MockHandle::create(); 487 std::unique_ptr<MockHandle> handle = MockHandle::create();
486 std::unique_ptr<MockReader> reader = MockReader::create(); 488 // |reader| will be adopted by |obtainFetchDataReader|.
489 MockReader* reader = MockReader::create().release();
487 490
488 Checkpoint checkpoint; 491 Checkpoint checkpoint;
489 InSequence s; 492 InSequence s;
490 493
491 EXPECT_CALL(*handle, obtainReaderInternal(_)).WillOnce(::testing::Return(rea der.get())); 494 EXPECT_CALL(*handle, obtainFetchDataReader(_)).WillOnce(Return(ByMove(WTF::w rapUnique(reader))));
492 EXPECT_CALL(checkpoint, Call(1)); 495 EXPECT_CALL(checkpoint, Call(1));
493 EXPECT_CALL(*reader, destruct()); 496 EXPECT_CALL(*reader, destruct());
494 EXPECT_CALL(*handle, destruct()); 497 EXPECT_CALL(*handle, destruct());
495 EXPECT_CALL(checkpoint, Call(2)); 498 EXPECT_CALL(checkpoint, Call(2));
496 499
497 // |reader| is adopted by |obtainReader|.
498 ASSERT_TRUE(reader.release());
499
500 BodyStreamBuffer* buffer = new BodyStreamBuffer(scope.getScriptState(), std: :move(handle)); 500 BodyStreamBuffer* buffer = new BodyStreamBuffer(scope.getScriptState(), std: :move(handle));
501 checkpoint.Call(1); 501 checkpoint.Call(1);
502 ScriptValue reason(scope.getScriptState(), v8String(scope.getScriptState()-> isolate(), "reason")); 502 ScriptValue reason(scope.getScriptState(), v8String(scope.getScriptState()-> isolate(), "reason"));
503 buffer->cancelSource(scope.getScriptState(), reason); 503 buffer->cancelSource(scope.getScriptState(), reason);
504 checkpoint.Call(2); 504 checkpoint.Call(2);
505 } 505 }
506 506
507 } // namespace 507 } // namespace
508 508
509 } // namespace blink 509 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698