OLD | NEW |
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 #include "config.h" | 5 #include "config.h" |
6 #include "modules/fetch/FetchDataLoader.h" | 6 #include "modules/fetch/FetchDataLoader.h" |
7 | 7 |
| 8 #include "modules/fetch/DataConsumerHandleTestUtil.h" |
| 9 |
8 #include <gmock/gmock.h> | 10 #include <gmock/gmock.h> |
9 #include <gtest/gtest.h> | 11 #include <gtest/gtest.h> |
10 | 12 |
11 namespace blink { | 13 namespace blink { |
12 | 14 |
13 namespace { | 15 namespace { |
14 | 16 |
15 using ::testing::InSequence; | 17 using ::testing::InSequence; |
16 using ::testing::Return; | 18 using ::testing::Return; |
17 using ::testing::DoAll; | 19 using ::testing::DoAll; |
18 using ::testing::StrictMock; | 20 using ::testing::StrictMock; |
19 using ::testing::_; | 21 using ::testing::_; |
20 using ::testing::SaveArg; | 22 using ::testing::SaveArg; |
21 using ::testing::SetArgPointee; | 23 using ::testing::SetArgPointee; |
22 using Checkpoint = StrictMock<::testing::MockFunction<void(int)>>; | 24 using Checkpoint = StrictMock<::testing::MockFunction<void(int)>>; |
| 25 using MockFetchDataLoaderClient = DataConsumerHandleTestUtil::MockFetchDataLoade
rClient; |
23 | 26 |
24 const WebDataConsumerHandle::Result kOk = WebDataConsumerHandle::Ok; | 27 const WebDataConsumerHandle::Result kOk = WebDataConsumerHandle::Ok; |
25 const WebDataConsumerHandle::Result kUnexpectedError = WebDataConsumerHandle::Un
expectedError; | 28 const WebDataConsumerHandle::Result kUnexpectedError = WebDataConsumerHandle::Un
expectedError; |
26 const WebDataConsumerHandle::Result kDone = WebDataConsumerHandle::Done; | 29 const WebDataConsumerHandle::Result kDone = WebDataConsumerHandle::Done; |
27 const WebDataConsumerHandle::Flags kNone = WebDataConsumerHandle::FlagNone; | 30 const WebDataConsumerHandle::Flags kNone = WebDataConsumerHandle::FlagNone; |
28 | 31 |
29 class MockReader : public FetchDataConsumerHandle::Reader { | 32 class MockReader : public FetchDataConsumerHandle::Reader { |
30 public: | 33 public: |
31 static PassOwnPtr<StrictMock<MockReader>> create() { return adoptPtr(new Str
ictMock<MockReader>); } | 34 static PassOwnPtr<StrictMock<MockReader>> create() { return adoptPtr(new Str
ictMock<MockReader>); } |
32 | 35 |
(...skipping 11 matching lines...) Expand all Loading... |
44 MOCK_METHOD0(destruct, void()); | 47 MOCK_METHOD0(destruct, void()); |
45 }; | 48 }; |
46 | 49 |
47 class MockHandle : public FetchDataConsumerHandle { | 50 class MockHandle : public FetchDataConsumerHandle { |
48 public: | 51 public: |
49 static PassOwnPtr<StrictMock<MockHandle>> create() { return adoptPtr(new Str
ictMock<MockHandle>); } | 52 static PassOwnPtr<StrictMock<MockHandle>> create() { return adoptPtr(new Str
ictMock<MockHandle>); } |
50 | 53 |
51 MOCK_METHOD1(obtainReaderInternal, Reader*(Client*)); | 54 MOCK_METHOD1(obtainReaderInternal, Reader*(Client*)); |
52 }; | 55 }; |
53 | 56 |
54 class MockFetchDataLoaderClient : public GarbageCollectedFinalized<MockFetchData
LoaderClient>, public FetchDataLoader::Client { | |
55 USING_GARBAGE_COLLECTED_MIXIN(MockFetchDataLoaderClient); | |
56 public: | |
57 static StrictMock<MockFetchDataLoaderClient>* create() { return new StrictMo
ck<MockFetchDataLoaderClient>; } | |
58 | |
59 DEFINE_INLINE_VIRTUAL_TRACE() | |
60 { | |
61 FetchDataLoader::Client::trace(visitor); | |
62 } | |
63 | |
64 MOCK_METHOD1(didFetchDataLoadedBlobHandleMock, void(RefPtr<BlobDataHandle>))
; | |
65 MOCK_METHOD1(didFetchDataLoadedArrayBufferMock, void(RefPtr<DOMArrayBuffer>)
); | |
66 MOCK_METHOD1(didFetchDataLoadedString, void(const String&)); | |
67 MOCK_METHOD0(didFetchDataLoadFailed, void()); | |
68 | |
69 // In mock methods we use RefPtr<> rather than PassRefPtr<>. | |
70 void didFetchDataLoadedArrayBuffer(PassRefPtr<DOMArrayBuffer> arrayBuffer) o
verride | |
71 { | |
72 didFetchDataLoadedArrayBufferMock(arrayBuffer); | |
73 } | |
74 void didFetchDataLoadedBlobHandle(PassRefPtr<BlobDataHandle> blobDataHandle)
override | |
75 { | |
76 didFetchDataLoadedBlobHandleMock(blobDataHandle); | |
77 } | |
78 }; | |
79 | |
80 const char kQuickBrownFox[] = "Quick brown fox"; | 57 const char kQuickBrownFox[] = "Quick brown fox"; |
81 const size_t kQuickBrownFoxLength = 15; | 58 const size_t kQuickBrownFoxLength = 15; |
82 const size_t kQuickBrownFoxLengthWithTerminatingNull = 16; | 59 const size_t kQuickBrownFoxLengthWithTerminatingNull = 16; |
83 | 60 |
84 TEST(FetchDataLoaderTest, LoadAsBlob) | 61 TEST(FetchDataLoaderTest, LoadAsBlob) |
85 { | 62 { |
86 WebDataConsumerHandle::Client *client = nullptr; | 63 WebDataConsumerHandle::Client *client = nullptr; |
87 Checkpoint checkpoint; | 64 Checkpoint checkpoint; |
88 | 65 |
89 OwnPtr<MockHandle> handle = MockHandle::create(); | 66 OwnPtr<MockHandle> handle = MockHandle::create(); |
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
491 checkpoint.Call(1); | 468 checkpoint.Call(1); |
492 fetchDataLoader->start(handle.get(), fetchDataLoaderClient); | 469 fetchDataLoader->start(handle.get(), fetchDataLoaderClient); |
493 checkpoint.Call(2); | 470 checkpoint.Call(2); |
494 fetchDataLoader->cancel(); | 471 fetchDataLoader->cancel(); |
495 checkpoint.Call(3); | 472 checkpoint.Call(3); |
496 } | 473 } |
497 | 474 |
498 } // namespace | 475 } // namespace |
499 | 476 |
500 } // namespace blink | 477 } // namespace blink |
OLD | NEW |