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

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

Issue 2584423002: Loading: move core/fetch to platform/loader/fetch (Closed)
Patch Set: another try Created 3 years, 10 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
(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 "platform/network/ResourceTimingInfo.h"
11 #include "platform/scheduler/test/fake_web_task_runner.h"
12 #include "wtf/PtrUtil.h"
13
14 #include <memory>
15
16 namespace blink {
17
18 class KURL;
19 class ResourceRequest;
20 class WebTaskRunner;
21 struct ResourceLoaderOptions;
22
23 // Mocked FetchContext for testing.
24 // TODO(toyoshim): Use this class by other unit tests that currently have own
25 // mocked FetchContext respectively.
26 class MockFetchContext : public FetchContext {
27 public:
28 enum LoadPolicy {
29 kShouldLoadNewResource,
30 kShouldNotLoadNewResource,
31 };
32 // TODO(toyoshim): Disallow to pass nullptr for |taskRunner|, and force to use
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));
39 }
40
41 ~MockFetchContext() override {}
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:
48 bool allowImage(bool imagesEnabled, const KURL&) const override {
49 return true;
50 }
51 ResourceRequestBlockedReason canRequest(
52 Resource::Type,
53 const ResourceRequest&,
54 const KURL&,
55 const ResourceLoaderOptions&,
56 bool forPreload,
57 FetchRequest::OriginRestriction) const override {
58 return ResourceRequestBlockedReason::None;
59 }
60 bool shouldLoadNewResource(Resource::Type) const override {
61 return m_loadPolicy == kShouldLoadNewResource;
62 }
63 RefPtr<WebTaskRunner> loadingTaskRunner() const override { return m_runner; }
64 CachePolicy getCachePolicy() const override { return m_policy; }
65 bool isLoadComplete() const override { return m_complete; }
66 void addResourceTiming(
67 const ResourceTimingInfo& resourceTimingInfo) override {
68 m_transferSize = resourceTimingInfo.transferSize();
69 }
70
71 private:
72 MockFetchContext(LoadPolicy loadPolicy, RefPtr<WebTaskRunner> taskRunner)
73 : m_loadPolicy(loadPolicy),
74 m_policy(CachePolicyVerify),
75 m_runner(taskRunner ? std::move(taskRunner)
76 : adoptRef(new scheduler::FakeWebTaskRunner)),
77 m_complete(false),
78 m_transferSize(-1) {}
79
80 enum LoadPolicy m_loadPolicy;
81 CachePolicy m_policy;
82 RefPtr<WebTaskRunner> m_runner;
83 bool m_complete;
84 long long m_transferSize;
85 };
86
87 } // namespace blink
88
89 #endif
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/fetch/MemoryCacheTest.cpp ('k') | third_party/WebKit/Source/core/fetch/MockResource.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698