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

Side by Side Diff: third_party/WebKit/Source/core/fetch/MockFetchContext.h

Issue 2644083003: ResourceFetcherTest: introduce FetchTestingPlatformSupport (Closed)
Patch Set: review #23 Created 3 years, 11 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 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 MockFetchContext_h 5 #ifndef MockFetchContext_h
6 #define MockFetchContext_h 6 #define MockFetchContext_h
7 7
8 #include "core/fetch/FetchContext.h" 8 #include "core/fetch/FetchContext.h"
9 #include "core/fetch/FetchRequest.h" 9 #include "core/fetch/FetchRequest.h"
10 #include "platform/network/ResourceTimingInfo.h" 10 #include "platform/network/ResourceTimingInfo.h"
(...skipping 11 matching lines...) Expand all
22 22
23 // Mocked FetchContext for testing. 23 // Mocked FetchContext for testing.
24 // TODO(toyoshim): Use this class by other unit tests that currently have own 24 // TODO(toyoshim): Use this class by other unit tests that currently have own
25 // mocked FetchContext respectively. 25 // mocked FetchContext respectively.
26 class MockFetchContext : public FetchContext { 26 class MockFetchContext : public FetchContext {
27 public: 27 public:
28 enum LoadPolicy { 28 enum LoadPolicy {
29 kShouldLoadNewResource, 29 kShouldLoadNewResource,
30 kShouldNotLoadNewResource, 30 kShouldNotLoadNewResource,
31 }; 31 };
32 static MockFetchContext* create(LoadPolicy loadPolicy) { 32 // TODO(toyoshim): Disallow to pass nullptr for |taskRunner|, and force to use
33 return new MockFetchContext(loadPolicy); 33 // FetchTestingPlatformSupport's WebTaskRunner. Probably, MockFetchContext
34 // would be available only through the FetchTestingPlatformSupport in the
35 // future.
36 static MockFetchContext* create(LoadPolicy loadPolicy,
37 RefPtr<WebTaskRunner> taskRunner = nullptr) {
38 return new MockFetchContext(loadPolicy, std::move(taskRunner));
34 } 39 }
35 40
36 ~MockFetchContext() override {} 41 ~MockFetchContext() override {}
37 42
43 void setCachePolicy(CachePolicy policy) { m_policy = policy; }
44 void setLoadComplete(bool complete) { m_complete = complete; }
45 long long getTransferSize() const { return m_transferSize; }
46
47 // FetchContext:
38 bool allowImage(bool imagesEnabled, const KURL&) const override { 48 bool allowImage(bool imagesEnabled, const KURL&) const override {
39 return true; 49 return true;
40 } 50 }
41 ResourceRequestBlockedReason canRequest( 51 ResourceRequestBlockedReason canRequest(
42 Resource::Type, 52 Resource::Type,
43 const ResourceRequest&, 53 const ResourceRequest&,
44 const KURL&, 54 const KURL&,
45 const ResourceLoaderOptions&, 55 const ResourceLoaderOptions&,
46 bool forPreload, 56 bool forPreload,
47 FetchRequest::OriginRestriction) const override { 57 FetchRequest::OriginRestriction) const override {
48 return ResourceRequestBlockedReason::None; 58 return ResourceRequestBlockedReason::None;
49 } 59 }
50 bool shouldLoadNewResource(Resource::Type) const override { 60 bool shouldLoadNewResource(Resource::Type) const override {
51 return m_loadPolicy == kShouldLoadNewResource; 61 return m_loadPolicy == kShouldLoadNewResource;
52 } 62 }
53 RefPtr<WebTaskRunner> loadingTaskRunner() const override { return m_runner; } 63 RefPtr<WebTaskRunner> loadingTaskRunner() const override { return m_runner; }
54
55 void setCachePolicy(CachePolicy policy) { m_policy = policy; }
56 CachePolicy getCachePolicy() const override { return m_policy; } 64 CachePolicy getCachePolicy() const override { return m_policy; }
57 void setLoadComplete(bool complete) { m_complete = complete; }
58 bool isLoadComplete() const override { return m_complete; } 65 bool isLoadComplete() const override { return m_complete; }
59
60 void addResourceTiming( 66 void addResourceTiming(
61 const ResourceTimingInfo& resourceTimingInfo) override { 67 const ResourceTimingInfo& resourceTimingInfo) override {
62 m_transferSize = resourceTimingInfo.transferSize(); 68 m_transferSize = resourceTimingInfo.transferSize();
63 } 69 }
64 long long getTransferSize() const { return m_transferSize; }
65 70
66 private: 71 private:
67 MockFetchContext(LoadPolicy loadPolicy) 72 MockFetchContext(LoadPolicy loadPolicy, RefPtr<WebTaskRunner> taskRunner)
68 : m_loadPolicy(loadPolicy), 73 : m_loadPolicy(loadPolicy),
69 m_policy(CachePolicyVerify), 74 m_policy(CachePolicyVerify),
70 m_runner(adoptRef(new scheduler::FakeWebTaskRunner)), 75 m_runner(taskRunner ? std::move(taskRunner)
76 : adoptRef(new scheduler::FakeWebTaskRunner)),
71 m_complete(false), 77 m_complete(false),
72 m_transferSize(-1) {} 78 m_transferSize(-1) {}
73 79
74 enum LoadPolicy m_loadPolicy; 80 enum LoadPolicy m_loadPolicy;
75 CachePolicy m_policy; 81 CachePolicy m_policy;
76 RefPtr<scheduler::FakeWebTaskRunner> m_runner; 82 RefPtr<WebTaskRunner> m_runner;
77 bool m_complete; 83 bool m_complete;
78 long long m_transferSize; 84 long long m_transferSize;
79 }; 85 };
80 86
81 } // namespace blink 87 } // namespace blink
82 88
83 #endif 89 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698