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

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

Issue 2495003002: Loading: Factor out ResourceFetcherMockFetchContext (Closed)
Patch Set: . Created 4 years, 1 month 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef MockFetchContext_h
6 #define MockFetchContext_h
7
8 #include "core/fetch/FetchContext.h"
9 #include "core/fetch/FetchRequest.h"
10 #include "core/fetch/ResourceLoaderOptions.h"
11 #include "platform/network/ResourceTimingInfo.h"
12 #include "platform/scheduler/test/fake_web_task_runner.h"
13 #include "wtf/PtrUtil.h"
14
yhirano 2016/11/14 04:49:13 +<memory>
Takashi Toyoshima 2016/11/14 05:34:31 Done.
15 namespace blink {
16
17 class KURL;
18 class ResourceRequest;
19 class WebTaskRunner;
20
21 // Mocked FetchContext for testing.
22 // TODO(toyoshim): Use this class by other unit tests that currently have own
23 // mocked FetchContext respectively.
24 class MockFetchContext : public FetchContext {
25 public:
26 enum LoadPolicy {
27 ShouldLoadNewResource,
28 ShouldNotLoadNewResource,
29 };
30 static MockFetchContext* create(LoadPolicy loadPolicy) {
31 return new MockFetchContext(loadPolicy);
32 }
33
34 virtual ~MockFetchContext() {}
yhirano 2016/11/14 04:49:13 +override -virtual
Takashi Toyoshima 2016/11/14 05:34:31 Done.
35
36 bool allowImage(bool imagesEnabled, const KURL&) const override {
37 return true;
38 }
39 bool canRequest(Resource::Type,
40 const ResourceRequest&,
41 const KURL&,
42 const ResourceLoaderOptions&,
43 bool forPreload,
44 FetchRequest::OriginRestriction) const override {
45 return true;
46 }
47 bool shouldLoadNewResource(Resource::Type) const override {
48 return m_loadPolicy == ShouldLoadNewResource;
49 }
50 WebTaskRunner* loadingTaskRunner() const override { return m_runner.get(); }
51
52 void setCachePolicy(CachePolicy policy) { m_policy = policy; }
53 CachePolicy getCachePolicy() const override { return m_policy; }
54 void setLoadComplete(bool complete) { m_complete = complete; }
55 bool isLoadComplete() const override { return m_complete; }
56
57 void addResourceTiming(
58 const ResourceTimingInfo& resourceTimingInfo) override {
59 m_transferSize = resourceTimingInfo.transferSize();
60 }
61 long long getTransferSize() const { return m_transferSize; }
62
63 private:
64 MockFetchContext(LoadPolicy loadPolicy)
65 : m_loadPolicy(loadPolicy),
66 m_policy(CachePolicyVerify),
67 m_runner(wrapUnique(new scheduler::FakeWebTaskRunner)),
68 m_complete(false),
69 m_transferSize(-1) {}
70
71 enum LoadPolicy m_loadPolicy;
72 CachePolicy m_policy;
73 std::unique_ptr<scheduler::FakeWebTaskRunner> m_runner;
74 bool m_complete;
75 long long m_transferSize;
76 };
77
78 } // namespace blink
79
80 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698