Index: Source/modules/fetch/DataConsumerHandleTestUtil.h |
diff --git a/Source/modules/fetch/DataConsumerHandleTestUtil.h b/Source/modules/fetch/DataConsumerHandleTestUtil.h |
index b60d2e6c7b22517ddb79f91d901acb83176d9dcd..785278f4ecb3c88efd098ee21f14a9533fb80ba7 100644 |
--- a/Source/modules/fetch/DataConsumerHandleTestUtil.h |
+++ b/Source/modules/fetch/DataConsumerHandleTestUtil.h |
@@ -10,6 +10,7 @@ |
#include "gin/public/isolate_holder.h" |
#include "modules/fetch/DataConsumerHandleUtil.h" |
#include "modules/fetch/FetchDataConsumerHandle.h" |
+#include "modules/fetch/FetchDataLoader.h" |
#include "platform/Task.h" |
#include "platform/ThreadSafeFunctional.h" |
#include "platform/WebThreadSupportingGC.h" |
@@ -211,6 +212,79 @@ public: |
OwnPtr<WebDataConsumerHandle> m_handle; |
}; |
+ |
+ class MockFetchDataLoaderClient : public GarbageCollectedFinalized<MockFetchDataLoaderClient>, public FetchDataLoader::Client { |
+ USING_GARBAGE_COLLECTED_MIXIN(MockFetchDataLoaderClient); |
+ public: |
+ static ::testing::StrictMock<MockFetchDataLoaderClient>* create() { return new ::testing::StrictMock<MockFetchDataLoaderClient>; } |
+ |
+ DEFINE_INLINE_VIRTUAL_TRACE() |
+ { |
+ FetchDataLoader::Client::trace(visitor); |
+ } |
+ |
+ MOCK_METHOD1(didFetchDataLoadedBlobHandleMock, void(RefPtr<BlobDataHandle>)); |
+ MOCK_METHOD1(didFetchDataLoadedArrayBufferMock, void(RefPtr<DOMArrayBuffer>)); |
+ MOCK_METHOD1(didFetchDataLoadedString, void(const String&)); |
+ MOCK_METHOD0(didFetchDataLoadFailed, void()); |
+ |
+ // In mock methods we use RefPtr<> rather than PassRefPtr<>. |
+ void didFetchDataLoadedArrayBuffer(PassRefPtr<DOMArrayBuffer> arrayBuffer) override |
+ { |
+ didFetchDataLoadedArrayBufferMock(arrayBuffer); |
+ } |
+ void didFetchDataLoadedBlobHandle(PassRefPtr<BlobDataHandle> blobDataHandle) override |
+ { |
+ didFetchDataLoadedBlobHandleMock(blobDataHandle); |
+ } |
+ }; |
+ |
+ // From https://codereview.chromium.org/1195563002/ |
+ |
+ class Command final { |
+ public: |
+ enum Name { |
+ Data, |
+ Done, |
+ Error, |
+ Wait, |
+ }; |
+ Command(Name name) : m_name(name) { } |
+ Command(Name name, const Vector<char>& body) : m_name(name), m_body(body) { } |
+ Command(Name name, const char* body, size_t size) : m_name(name) |
+ { |
+ m_body.append(body, size); |
+ } |
+ Command(Name name, const char* body) : Command(name, body, strlen(body)) { } |
+ Name name() const { return m_name; } |
+ const Vector<char>& body() const { return m_body; } |
+ |
+ private: |
+ const Name m_name; |
+ Vector<char> m_body; |
+ }; |
+ |
+ // ReplayingHandle stores commands via |add| and replays the stored commends when read. |
+ class ReplayingHandle final : public WebDataConsumerHandle { |
+ public: |
+ class Context; |
+ class ReaderImpl; |
+ |
+ ReplayingHandle(); |
+ ~ReplayingHandle(); |
+ Reader* obtainReaderInternal(Client*) override; |
+ |
+ // Add a command to this handle. This function must be called on the |
+ // creator thread. This function must be called BEFORE any reader is |
+ // obtained. |
+ void add(const Command&); |
+ |
+ Context* context() { return m_context.get(); }; |
+ |
+ private: |
+ RefPtr<Context> m_context; |
+ }; |
+ |
}; |
} // namespace blink |