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

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

Issue 2342233002: Remove Fetch[Blob|FormData]ConsumerHandle (Closed)
Patch Set: rebase Created 4 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 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/BlobBytesConsumer.h"
9 #include "modules/fetch/BytesConsumerTestUtil.h" 10 #include "modules/fetch/BytesConsumerTestUtil.h"
10 #include "modules/fetch/DataConsumerHandleTestUtil.h" 11 #include "modules/fetch/DataConsumerHandleTestUtil.h"
11 #include "modules/fetch/FetchBlobDataConsumerHandle.h" 12 #include "modules/fetch/FormDataBytesConsumer.h"
12 #include "modules/fetch/FetchFormDataConsumerHandle.h"
13 #include "platform/blob/BlobData.h" 13 #include "platform/blob/BlobData.h"
14 #include "platform/blob/BlobURL.h" 14 #include "platform/blob/BlobURL.h"
15 #include "platform/network/EncodedFormData.h" 15 #include "platform/network/EncodedFormData.h"
16 #include "platform/testing/UnitTestHelpers.h" 16 #include "platform/testing/UnitTestHelpers.h"
17 #include "testing/gmock/include/gmock/gmock.h" 17 #include "testing/gmock/include/gmock/gmock.h"
18 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
19 #include "wtf/PtrUtil.h" 19 #include "wtf/PtrUtil.h"
20 #include <memory> 20 #include <memory>
21 21
22 namespace blink { 22 namespace blink {
23 23
24 namespace { 24 namespace {
25 25
26 using ::testing::ByMove; 26 using ::testing::ByMove;
27 using ::testing::InSequence; 27 using ::testing::InSequence;
28 using ::testing::Return; 28 using ::testing::Return;
29 using ::testing::_; 29 using ::testing::_;
30 using ::testing::SaveArg; 30 using ::testing::SaveArg;
31 using Checkpoint = ::testing::StrictMock<::testing::MockFunction<void(int)>>; 31 using Checkpoint = ::testing::StrictMock<::testing::MockFunction<void(int)>>;
32 using Command = DataConsumerHandleTestUtil::Command; 32 using Command = DataConsumerHandleTestUtil::Command;
33 using ReplayingHandle = DataConsumerHandleTestUtil::ReplayingHandle; 33 using ReplayingHandle = DataConsumerHandleTestUtil::ReplayingHandle;
34 using MockFetchDataLoaderClient = DataConsumerHandleTestUtil::MockFetchDataLoade rClient; 34 using MockFetchDataLoaderClient = DataConsumerHandleTestUtil::MockFetchDataLoade rClient;
35 35
36 class FakeLoaderFactory : public FetchBlobDataConsumerHandle::LoaderFactory {
37 public:
38 ThreadableLoader* create(ExecutionContext&, ThreadableLoaderClient*, const T hreadableLoaderOptions&, const ResourceLoaderOptions&) override
39 {
40 ASSERT_NOT_REACHED();
41 return nullptr;
42 }
43 };
44
45 class BodyStreamBufferTest : public ::testing::Test { 36 class BodyStreamBufferTest : public ::testing::Test {
46 protected: 37 protected:
47 ScriptValue eval(ScriptState* scriptState, const char* s) 38 ScriptValue eval(ScriptState* scriptState, const char* s)
48 { 39 {
49 v8::Local<v8::String> source; 40 v8::Local<v8::String> source;
50 v8::Local<v8::Script> script; 41 v8::Local<v8::Script> script;
51 v8::MicrotasksScope microtasks(scriptState->isolate(), v8::MicrotasksSco pe::kDoNotRunMicrotasks); 42 v8::MicrotasksScope microtasks(scriptState->isolate(), v8::MicrotasksSco pe::kDoNotRunMicrotasks);
52 if (!v8Call(v8::String::NewFromUtf8(scriptState->isolate(), s, v8::NewSt ringType::kNormal), source)) { 43 if (!v8Call(v8::String::NewFromUtf8(scriptState->isolate(), s, v8::NewSt ringType::kNormal), source)) {
53 ADD_FAILURE(); 44 ADD_FAILURE();
54 return ScriptValue(); 45 return ScriptValue();
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 checkpoint.Call(4); 158 checkpoint.Call(4);
168 } 159 }
169 160
170 TEST_F(BodyStreamBufferTest, DrainAsBlobDataHandle) 161 TEST_F(BodyStreamBufferTest, DrainAsBlobDataHandle)
171 { 162 {
172 V8TestingScope scope; 163 V8TestingScope scope;
173 std::unique_ptr<BlobData> data = BlobData::create(); 164 std::unique_ptr<BlobData> data = BlobData::create();
174 data->appendText("hello", false); 165 data->appendText("hello", false);
175 auto size = data->length(); 166 auto size = data->length();
176 RefPtr<BlobDataHandle> blobDataHandle = BlobDataHandle::create(std::move(dat a), size); 167 RefPtr<BlobDataHandle> blobDataHandle = BlobDataHandle::create(std::move(dat a), size);
177 BodyStreamBuffer* buffer = new BodyStreamBuffer(scope.getScriptState(), Fetc hBlobDataConsumerHandle::create(scope.getExecutionContext(), blobDataHandle, new FakeLoaderFactory)); 168 BodyStreamBuffer* buffer = new BodyStreamBuffer(scope.getScriptState(), new BlobBytesConsumer(scope.getExecutionContext(), blobDataHandle));
178 169
179 EXPECT_FALSE(buffer->isStreamLocked()); 170 EXPECT_FALSE(buffer->isStreamLocked());
180 EXPECT_FALSE(buffer->isStreamDisturbed()); 171 EXPECT_FALSE(buffer->isStreamDisturbed());
181 EXPECT_FALSE(buffer->hasPendingActivity()); 172 EXPECT_FALSE(buffer->hasPendingActivity());
182 RefPtr<BlobDataHandle> outputBlobDataHandle = buffer->drainAsBlobDataHandle( BytesConsumer::BlobSizePolicy::AllowBlobWithInvalidSize); 173 RefPtr<BlobDataHandle> outputBlobDataHandle = buffer->drainAsBlobDataHandle( BytesConsumer::BlobSizePolicy::AllowBlobWithInvalidSize);
183 174
184 EXPECT_TRUE(buffer->isStreamLocked()); 175 EXPECT_TRUE(buffer->isStreamLocked());
185 EXPECT_TRUE(buffer->isStreamDisturbed()); 176 EXPECT_TRUE(buffer->isStreamDisturbed());
186 EXPECT_FALSE(buffer->hasPendingActivity()); 177 EXPECT_FALSE(buffer->hasPendingActivity());
187 EXPECT_EQ(blobDataHandle, outputBlobDataHandle); 178 EXPECT_EQ(blobDataHandle, outputBlobDataHandle);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 } 216 }
226 217
227 TEST_F(BodyStreamBufferTest, DrainAsFormData) 218 TEST_F(BodyStreamBufferTest, DrainAsFormData)
228 { 219 {
229 V8TestingScope scope; 220 V8TestingScope scope;
230 FormData* data = FormData::create(UTF8Encoding()); 221 FormData* data = FormData::create(UTF8Encoding());
231 data->append("name1", "value1"); 222 data->append("name1", "value1");
232 data->append("name2", "value2"); 223 data->append("name2", "value2");
233 RefPtr<EncodedFormData> inputFormData = data->encodeMultiPartFormData(); 224 RefPtr<EncodedFormData> inputFormData = data->encodeMultiPartFormData();
234 225
235 BodyStreamBuffer* buffer = new BodyStreamBuffer(scope.getScriptState(), Fetc hFormDataConsumerHandle::create(scope.getExecutionContext(), inputFormData)); 226 BodyStreamBuffer* buffer = new BodyStreamBuffer(scope.getScriptState(), new FormDataBytesConsumer(scope.getExecutionContext(), inputFormData));
236 227
237 EXPECT_FALSE(buffer->isStreamLocked()); 228 EXPECT_FALSE(buffer->isStreamLocked());
238 EXPECT_FALSE(buffer->isStreamDisturbed()); 229 EXPECT_FALSE(buffer->isStreamDisturbed());
239 EXPECT_FALSE(buffer->hasPendingActivity()); 230 EXPECT_FALSE(buffer->hasPendingActivity());
240 RefPtr<EncodedFormData> outputFormData = buffer->drainAsFormData(); 231 RefPtr<EncodedFormData> outputFormData = buffer->drainAsFormData();
241 232
242 EXPECT_TRUE(buffer->isStreamLocked()); 233 EXPECT_TRUE(buffer->isStreamLocked());
243 EXPECT_TRUE(buffer->isStreamDisturbed()); 234 EXPECT_TRUE(buffer->isStreamDisturbed());
244 EXPECT_FALSE(buffer->hasPendingActivity()); 235 EXPECT_FALSE(buffer->hasPendingActivity());
245 EXPECT_EQ(outputFormData->flattenToString(), inputFormData->flattenToString( )); 236 EXPECT_EQ(outputFormData->flattenToString(), inputFormData->flattenToString( ));
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
472 BodyStreamBuffer* buffer = new BodyStreamBuffer(scope.getScriptState(), cons umer); 463 BodyStreamBuffer* buffer = new BodyStreamBuffer(scope.getScriptState(), cons umer);
473 ScriptValue reason(scope.getScriptState(), v8String(scope.getScriptState()-> isolate(), "reason")); 464 ScriptValue reason(scope.getScriptState(), v8String(scope.getScriptState()-> isolate(), "reason"));
474 EXPECT_FALSE(consumer->isCancelled()); 465 EXPECT_FALSE(consumer->isCancelled());
475 buffer->cancel(scope.getScriptState(), reason); 466 buffer->cancel(scope.getScriptState(), reason);
476 EXPECT_TRUE(consumer->isCancelled()); 467 EXPECT_TRUE(consumer->isCancelled());
477 } 468 }
478 469
479 } // namespace 470 } // namespace
480 471
481 } // namespace blink 472 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/modules/fetch/BUILD.gn ('k') | third_party/WebKit/Source/modules/fetch/BytesConsumer.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698