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

Side by Side Diff: Source/modules/fetch/DataConsumerHandleTestUtil.h

Issue 1192913007: Change BodyStreamBuffer to be FetchDataConsumerHandle-based and enable backpressure in Fetch API (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rebase. Created 5 years, 6 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 #ifndef DataConsumerHandleTestUtil_h 5 #ifndef DataConsumerHandleTestUtil_h
6 #define DataConsumerHandleTestUtil_h 6 #define DataConsumerHandleTestUtil_h
7 7
8 #include "bindings/core/v8/ScriptState.h" 8 #include "bindings/core/v8/ScriptState.h"
9 #include "core/testing/NullExecutionContext.h" 9 #include "core/testing/NullExecutionContext.h"
10 #include "gin/public/isolate_holder.h" 10 #include "gin/public/isolate_holder.h"
11 #include "modules/fetch/DataConsumerHandleUtil.h" 11 #include "modules/fetch/DataConsumerHandleUtil.h"
12 #include "modules/fetch/FetchDataConsumerHandle.h" 12 #include "modules/fetch/FetchDataConsumerHandle.h"
13 #include "modules/fetch/FetchDataLoader.h"
13 #include "platform/Task.h" 14 #include "platform/Task.h"
14 #include "platform/ThreadSafeFunctional.h" 15 #include "platform/ThreadSafeFunctional.h"
15 #include "platform/WebThreadSupportingGC.h" 16 #include "platform/WebThreadSupportingGC.h"
16 #include "platform/heap/Handle.h" 17 #include "platform/heap/Handle.h"
17 #include "public/platform/Platform.h" 18 #include "public/platform/Platform.h"
18 #include "public/platform/WebDataConsumerHandle.h" 19 #include "public/platform/WebDataConsumerHandle.h"
19 #include "public/platform/WebTraceLocation.h" 20 #include "public/platform/WebTraceLocation.h"
20 #include "public/platform/WebWaitableEvent.h" 21 #include "public/platform/WebWaitableEvent.h"
21 #include "wtf/Locker.h" 22 #include "wtf/Locker.h"
22 23
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 m_reader = nullptr; 205 m_reader = nullptr;
205 readingThread()->postTask(FROM_HERE, new Task(threadSafeBind(&Self:: signalDone, this))); 206 readingThread()->postTask(FROM_HERE, new Task(threadSafeBind(&Self:: signalDone, this)));
206 } 207 }
207 void didGetReadable() override 208 void didGetReadable() override
208 { 209 {
209 ASSERT_NOT_REACHED(); 210 ASSERT_NOT_REACHED();
210 } 211 }
211 212
212 OwnPtr<WebDataConsumerHandle> m_handle; 213 OwnPtr<WebDataConsumerHandle> m_handle;
213 }; 214 };
215
216 class MockFetchDataLoaderClient : public GarbageCollectedFinalized<MockFetch DataLoaderClient>, public FetchDataLoader::Client {
217 USING_GARBAGE_COLLECTED_MIXIN(MockFetchDataLoaderClient);
218 public:
219 static ::testing::StrictMock<MockFetchDataLoaderClient>* create() { retu rn new ::testing::StrictMock<MockFetchDataLoaderClient>; }
220
221 DEFINE_INLINE_VIRTUAL_TRACE()
222 {
223 FetchDataLoader::Client::trace(visitor);
224 }
225
226 MOCK_METHOD1(didFetchDataLoadedBlobHandleMock, void(RefPtr<BlobDataHandl e>));
227 MOCK_METHOD1(didFetchDataLoadedArrayBufferMock, void(RefPtr<DOMArrayBuff er>));
228 MOCK_METHOD1(didFetchDataLoadedString, void(const String&));
229 MOCK_METHOD0(didFetchDataLoadFailed, void());
230
231 // In mock methods we use RefPtr<> rather than PassRefPtr<>.
232 void didFetchDataLoadedArrayBuffer(PassRefPtr<DOMArrayBuffer> arrayBuffe r) override
233 {
234 didFetchDataLoadedArrayBufferMock(arrayBuffer);
235 }
236 void didFetchDataLoadedBlobHandle(PassRefPtr<BlobDataHandle> blobDataHan dle) override
237 {
238 didFetchDataLoadedBlobHandleMock(blobDataHandle);
239 }
240 };
241
242 // From https://codereview.chromium.org/1195563002/
243
244 class Command final {
245 public:
246 enum Name {
247 Data,
248 Done,
249 Error,
250 Wait,
251 };
252 Command(Name name) : m_name(name) { }
253 Command(Name name, const Vector<char>& body) : m_name(name), m_body(body ) { }
254 Command(Name name, const char* body, size_t size) : m_name(name)
255 {
256 m_body.append(body, size);
257 }
258 Command(Name name, const char* body) : Command(name, body, strlen(body)) { }
259 Name name() const { return m_name; }
260 const Vector<char>& body() const { return m_body; }
261
262 private:
263 const Name m_name;
264 Vector<char> m_body;
265 };
266
267 // ReplayingHandle stores commands via |add| and replays the stored commends when read.
268 class ReplayingHandle final : public WebDataConsumerHandle {
269 public:
270 class Context;
271 class ReaderImpl;
272
273 ReplayingHandle();
274 ~ReplayingHandle();
275 Reader* obtainReaderInternal(Client*) override;
276
277 // Add a command to this handle. This function must be called on the
278 // creator thread. This function must be called BEFORE any reader is
279 // obtained.
280 void add(const Command&);
281
282 Context* context() { return m_context.get(); };
283
284 private:
285 RefPtr<Context> m_context;
286 };
287
214 }; 288 };
215 289
216 } // namespace blink 290 } // namespace blink
217 291
218 #endif // DataConsumerHandleTestUtil_h 292 #endif // DataConsumerHandleTestUtil_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698