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

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: rebase 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
(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 static MockFetchContext* create(LoadPolicy loadPolicy) {
33 return new MockFetchContext(loadPolicy);
34 }
35
36 ~MockFetchContext() override {}
37
38 bool allowImage(bool imagesEnabled, const KURL&) const override {
39 return true;
40 }
41 ResourceRequestBlockedReason canRequest(
42 Resource::Type,
43 const ResourceRequest&,
44 const KURL&,
45 const ResourceLoaderOptions&,
46 bool forPreload,
47 FetchRequest::OriginRestriction) const override {
48 return ResourceRequestBlockedReason::None;
49 }
50 bool shouldLoadNewResource(Resource::Type) const override {
51 return m_loadPolicy == kShouldLoadNewResource;
52 }
53 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; }
57 void setLoadComplete(bool complete) { m_complete = complete; }
58 bool isLoadComplete() const override { return m_complete; }
59
60 void addResourceTiming(
61 const ResourceTimingInfo& resourceTimingInfo) override {
62 m_transferSize = resourceTimingInfo.transferSize();
63 }
64 long long getTransferSize() const { return m_transferSize; }
65
66 private:
67 MockFetchContext(LoadPolicy loadPolicy)
68 : m_loadPolicy(loadPolicy),
69 m_policy(CachePolicyVerify),
70 m_runner(adoptRef(new scheduler::FakeWebTaskRunner)),
71 m_complete(false),
72 m_transferSize(-1) {}
73
74 enum LoadPolicy m_loadPolicy;
75 CachePolicy m_policy;
76 RefPtr<scheduler::FakeWebTaskRunner> m_runner;
77 bool m_complete;
78 long long m_transferSize;
79 };
80
81 } // namespace blink
82
83 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698