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

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

Issue 1899163002: BodyStreamBuffer's drainAs* function should lock stream (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@body-stream-buffer-test-refactoring
Patch Set: Created 4 years, 8 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 "core/html/FormData.h"
7 #include "core/testing/DummyPageHolder.h" 8 #include "core/testing/DummyPageHolder.h"
8 #include "modules/fetch/DataConsumerHandleTestUtil.h" 9 #include "modules/fetch/DataConsumerHandleTestUtil.h"
10 #include "modules/fetch/FetchBlobDataConsumerHandle.h"
11 #include "modules/fetch/FetchFormDataConsumerHandle.h"
12 #include "platform/blob/BlobData.h"
13 #include "platform/blob/BlobURL.h"
14 #include "platform/network/EncodedFormData.h"
9 #include "platform/testing/UnitTestHelpers.h" 15 #include "platform/testing/UnitTestHelpers.h"
10 #include "testing/gmock/include/gmock/gmock.h" 16 #include "testing/gmock/include/gmock/gmock.h"
11 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
12 #include "wtf/OwnPtr.h" 18 #include "wtf/OwnPtr.h"
13 19
14 namespace blink { 20 namespace blink {
15 21
16 namespace { 22 namespace {
17 23
18 using ::testing::InSequence; 24 using ::testing::InSequence;
19 using ::testing::_; 25 using ::testing::_;
20 using ::testing::SaveArg; 26 using ::testing::SaveArg;
21 using Checkpoint = ::testing::StrictMock<::testing::MockFunction<void(int)>>; 27 using Checkpoint = ::testing::StrictMock<::testing::MockFunction<void(int)>>;
22 using Command = DataConsumerHandleTestUtil::Command; 28 using Command = DataConsumerHandleTestUtil::Command;
23 using ReplayingHandle = DataConsumerHandleTestUtil::ReplayingHandle; 29 using ReplayingHandle = DataConsumerHandleTestUtil::ReplayingHandle;
24 using MockFetchDataLoaderClient = DataConsumerHandleTestUtil::MockFetchDataLoade rClient; 30 using MockFetchDataLoaderClient = DataConsumerHandleTestUtil::MockFetchDataLoade rClient;
25 31
32 class FakeLoaderFactory : public FetchBlobDataConsumerHandle::LoaderFactory {
33 public:
34 PassOwnPtr<ThreadableLoader> create(ExecutionContext&, ThreadableLoaderClien t*, const ThreadableLoaderOptions&, const ResourceLoaderOptions&) override
35 {
36 ASSERT_NOT_REACHED();
37 return nullptr;
38 }
39 };
40
26 class BodyStreamBufferTest : public ::testing::Test { 41 class BodyStreamBufferTest : public ::testing::Test {
27 public: 42 public:
28 BodyStreamBufferTest() 43 BodyStreamBufferTest()
29 { 44 {
30 m_page = DummyPageHolder::create(IntSize(1, 1)); 45 m_page = DummyPageHolder::create(IntSize(1, 1));
31 } 46 }
32 ~BodyStreamBufferTest() override {} 47 ~BodyStreamBufferTest() override {}
33 48
34 protected: 49 protected:
35 ScriptState* getScriptState() { return ScriptState::forMainWorld(m_page->doc ument().frame()); } 50 ScriptState* getScriptState() { return ScriptState::forMainWorld(m_page->doc ument().frame()); }
(...skipping 14 matching lines...) Expand all
50 EXPECT_TRUE(buffer->isStreamReadable()); 65 EXPECT_TRUE(buffer->isStreamReadable());
51 66
52 OwnPtr<FetchDataConsumerHandle> handle2 = buffer->releaseHandle(getExecution Context()); 67 OwnPtr<FetchDataConsumerHandle> handle2 = buffer->releaseHandle(getExecution Context());
53 68
54 ASSERT_EQ(rawHandle, handle2.get()); 69 ASSERT_EQ(rawHandle, handle2.get());
55 EXPECT_TRUE(buffer->isStreamLocked()); 70 EXPECT_TRUE(buffer->isStreamLocked());
56 EXPECT_TRUE(buffer->isStreamDisturbed()); 71 EXPECT_TRUE(buffer->isStreamDisturbed());
57 EXPECT_TRUE(buffer->isStreamClosed()); 72 EXPECT_TRUE(buffer->isStreamClosed());
58 } 73 }
59 74
75 TEST_F(BodyStreamBufferTest, DrainAsBlobDataHandle)
76 {
77 OwnPtr<BlobData> data = BlobData::create();
78 data->appendText("hello", false);
79 auto size = data->length();
80 RefPtr<BlobDataHandle> blobDataHandle = BlobDataHandle::create(data.release( ), size);
81 BodyStreamBuffer* buffer = new BodyStreamBuffer(FetchBlobDataConsumerHandle: :create(getExecutionContext(), blobDataHandle, new FakeLoaderFactory));
82
83 EXPECT_FALSE(buffer->isStreamLocked());
84 EXPECT_FALSE(buffer->isStreamDisturbed());
85 EXPECT_FALSE(buffer->hasPendingActivity());
86 RefPtr<BlobDataHandle> outputBlobDataHandle = buffer->drainAsBlobDataHandle( getExecutionContext(), FetchDataConsumerHandle::Reader::AllowBlobWithInvalidSize );
87
88 EXPECT_TRUE(buffer->isStreamLocked());
89 EXPECT_TRUE(buffer->isStreamDisturbed());
90 EXPECT_FALSE(buffer->hasPendingActivity());
91 EXPECT_EQ(blobDataHandle, outputBlobDataHandle);
92 }
93
94 TEST_F(BodyStreamBufferTest, DrainAsBlobDataHandleReturnsNull)
95 {
96 BodyStreamBuffer* buffer = new BodyStreamBuffer(createFetchDataConsumerHandl eFromWebHandle(createWaitingDataConsumerHandle()));
tyoshino (SeeGerritForStatus) 2016/04/21 06:47:42 add a comment here or in DataConsumerHandleUtil.h
yhirano 2016/04/21 08:22:35 Done.
97
98 EXPECT_FALSE(buffer->isStreamLocked());
99 EXPECT_FALSE(buffer->isStreamDisturbed());
100 EXPECT_FALSE(buffer->hasPendingActivity());
101
102 EXPECT_FALSE(buffer->drainAsBlobDataHandle(getExecutionContext(), FetchDataC onsumerHandle::Reader::AllowBlobWithInvalidSize));
103
104 EXPECT_FALSE(buffer->isStreamLocked());
105 EXPECT_FALSE(buffer->isStreamDisturbed());
106 EXPECT_FALSE(buffer->hasPendingActivity());
107 }
108
109 TEST_F(BodyStreamBufferTest, DrainAsFormData)
110 {
111 FormData* data = FormData::create(UTF8Encoding());
112 data->append("name1", "value1");
113 data->append("name2", "value2");
114 RefPtr<EncodedFormData> inputFormData = data->encodeMultiPartFormData();
115
116 BodyStreamBuffer* buffer = new BodyStreamBuffer(FetchFormDataConsumerHandle: :create(getExecutionContext(), inputFormData));
117
118 EXPECT_FALSE(buffer->isStreamLocked());
119 EXPECT_FALSE(buffer->isStreamDisturbed());
120 EXPECT_FALSE(buffer->hasPendingActivity());
121 RefPtr<EncodedFormData> outputFormData = buffer->drainAsFormData(getExecutio nContext());
122
123 EXPECT_TRUE(buffer->isStreamLocked());
124 EXPECT_TRUE(buffer->isStreamDisturbed());
125 EXPECT_FALSE(buffer->hasPendingActivity());
126 EXPECT_EQ(outputFormData->flattenToString(), inputFormData->flattenToString( ));
127 }
128
129 TEST_F(BodyStreamBufferTest, DrainAsFormDataReturnsNull)
130 {
131 BodyStreamBuffer* buffer = new BodyStreamBuffer(createFetchDataConsumerHandl eFromWebHandle(createWaitingDataConsumerHandle()));
132
133 EXPECT_FALSE(buffer->isStreamLocked());
134 EXPECT_FALSE(buffer->isStreamDisturbed());
135 EXPECT_FALSE(buffer->hasPendingActivity());
136
137 EXPECT_FALSE(buffer->drainAsFormData(getExecutionContext()));
138
139 EXPECT_FALSE(buffer->isStreamLocked());
140 EXPECT_FALSE(buffer->isStreamDisturbed());
141 EXPECT_FALSE(buffer->hasPendingActivity());
142 }
143
60 TEST_F(BodyStreamBufferTest, LoadBodyStreamBufferAsArrayBuffer) 144 TEST_F(BodyStreamBufferTest, LoadBodyStreamBufferAsArrayBuffer)
61 { 145 {
62 Checkpoint checkpoint; 146 Checkpoint checkpoint;
63 MockFetchDataLoaderClient* client = MockFetchDataLoaderClient::create(); 147 MockFetchDataLoaderClient* client = MockFetchDataLoaderClient::create();
64 DOMArrayBuffer* arrayBuffer = nullptr; 148 DOMArrayBuffer* arrayBuffer = nullptr;
65 149
66 InSequence s; 150 InSequence s;
67 EXPECT_CALL(checkpoint, Call(1)); 151 EXPECT_CALL(checkpoint, Call(1));
68 EXPECT_CALL(*client, didFetchDataLoadedArrayBufferMock(_)).WillOnce(SaveArg< 0>(&arrayBuffer)); 152 EXPECT_CALL(*client, didFetchDataLoadedArrayBufferMock(_)).WillOnce(SaveArg< 0>(&arrayBuffer));
69 EXPECT_CALL(checkpoint, Call(2)); 153 EXPECT_CALL(checkpoint, Call(2));
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 BodyStreamBuffer* buffer = new BodyStreamBuffer(handle.release()); 395 BodyStreamBuffer* buffer = new BodyStreamBuffer(handle.release());
312 checkpoint.Call(1); 396 checkpoint.Call(1);
313 ScriptValue reason(getScriptState(), v8String(getScriptState()->isolate(), " reason")); 397 ScriptValue reason(getScriptState(), v8String(getScriptState()->isolate(), " reason"));
314 buffer->cancelSource(getScriptState(), reason); 398 buffer->cancelSource(getScriptState(), reason);
315 checkpoint.Call(2); 399 checkpoint.Call(2);
316 } 400 }
317 401
318 } // namespace 402 } // namespace
319 403
320 } // namespace blink 404 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/modules/fetch/BodyStreamBuffer.cpp ('k') | third_party/WebKit/Source/modules/fetch/FetchManager.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698