| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 BytesConsumerTestUtil_h | 5 #ifndef BytesConsumerTestUtil_h |
| 6 #define BytesConsumerTestUtil_h | 6 #define BytesConsumerTestUtil_h |
| 7 | 7 |
| 8 #include "modules/fetch/BytesConsumer.h" | 8 #include "modules/fetch/BytesConsumer.h" |
| 9 #include "modules/fetch/FetchDataLoader.h" |
| 9 #include "platform/heap/Handle.h" | 10 #include "platform/heap/Handle.h" |
| 11 #include "testing/gmock/include/gmock/gmock.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" |
| 10 #include "wtf/Deque.h" | 13 #include "wtf/Deque.h" |
| 11 #include "wtf/Vector.h" | 14 #include "wtf/Vector.h" |
| 12 | 15 |
| 13 namespace blink { | 16 namespace blink { |
| 14 | 17 |
| 15 class ExecutionContext; | 18 class ExecutionContext; |
| 16 | 19 |
| 17 class BytesConsumerTestUtil { | 20 class BytesConsumerTestUtil { |
| 18 STATIC_ONLY(BytesConsumerTestUtil); | 21 STATIC_ONLY(BytesConsumerTestUtil); |
| 19 public: | 22 public: |
| 23 class MockBytesConsumer : public BytesConsumer { |
| 24 public: |
| 25 static MockBytesConsumer* create() { return new ::testing::StrictMock<Mo
ckBytesConsumer>(); } |
| 26 |
| 27 MOCK_METHOD2(beginRead, Result(const char**, size_t*)); |
| 28 MOCK_METHOD1(endRead, Result(size_t)); |
| 29 MOCK_METHOD1(drainAsBlobDataHandle, PassRefPtr<BlobDataHandle>(BlobSizeP
olicy)); |
| 30 MOCK_METHOD0(drainAsFormData, PassRefPtr<EncodedFormData>()); |
| 31 MOCK_METHOD1(setClient, void(Client*)); |
| 32 MOCK_METHOD0(clearClient, void()); |
| 33 MOCK_METHOD0(cancel, void()); |
| 34 MOCK_CONST_METHOD0(getPublicState, PublicState()); |
| 35 MOCK_CONST_METHOD0(getError, Error()); |
| 36 |
| 37 String debugName() const override { return "MockBytesConsumer"; } |
| 38 |
| 39 protected: |
| 40 MockBytesConsumer(); |
| 41 }; |
| 42 |
| 43 class MockFetchDataLoaderClient : public GarbageCollectedFinalized<MockFetch
DataLoaderClient>, public FetchDataLoader::Client { |
| 44 USING_GARBAGE_COLLECTED_MIXIN(MockFetchDataLoaderClient); |
| 45 public: |
| 46 static ::testing::StrictMock<MockFetchDataLoaderClient>* create() { retu
rn new ::testing::StrictMock<MockFetchDataLoaderClient>; } |
| 47 |
| 48 DEFINE_INLINE_VIRTUAL_TRACE() |
| 49 { |
| 50 FetchDataLoader::Client::trace(visitor); |
| 51 } |
| 52 |
| 53 MOCK_METHOD1(didFetchDataLoadedBlobHandleMock, void(RefPtr<BlobDataHandl
e>)); |
| 54 MOCK_METHOD1(didFetchDataLoadedArrayBufferMock, void(DOMArrayBuffer*)); |
| 55 MOCK_METHOD1(didFetchDataLoadedString, void(const String&)); |
| 56 MOCK_METHOD0(didFetchDataLoadStream, void()); |
| 57 MOCK_METHOD0(didFetchDataLoadFailed, void()); |
| 58 |
| 59 void didFetchDataLoadedArrayBuffer(DOMArrayBuffer* arrayBuffer) override |
| 60 { |
| 61 didFetchDataLoadedArrayBufferMock(arrayBuffer); |
| 62 } |
| 63 // In mock methods we use RefPtr<> rather than PassRefPtr<>. |
| 64 void didFetchDataLoadedBlobHandle(PassRefPtr<BlobDataHandle> blobDataHan
dle) override |
| 65 { |
| 66 didFetchDataLoadedBlobHandleMock(blobDataHandle); |
| 67 } |
| 68 }; |
| 69 |
| 20 class Command final { | 70 class Command final { |
| 21 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); | 71 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); |
| 22 public: | 72 public: |
| 23 enum Name { | 73 enum Name { |
| 24 Data, | 74 Data, |
| 25 Done, | 75 Done, |
| 26 Error, | 76 Error, |
| 27 Wait, | 77 Wait, |
| 28 }; | 78 }; |
| 29 | 79 |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 private: | 151 private: |
| 102 Member<BytesConsumer> m_consumer; | 152 Member<BytesConsumer> m_consumer; |
| 103 BytesConsumer::Result m_result = BytesConsumer::Result::ShouldWait; | 153 BytesConsumer::Result m_result = BytesConsumer::Result::ShouldWait; |
| 104 Vector<char> m_data; | 154 Vector<char> m_data; |
| 105 }; | 155 }; |
| 106 }; | 156 }; |
| 107 | 157 |
| 108 } // namespace blink | 158 } // namespace blink |
| 109 | 159 |
| 110 #endif // BytesConsumerTestUtil_h | 160 #endif // BytesConsumerTestUtil_h |
| OLD | NEW |