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

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

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

Powered by Google App Engine
This is Rietveld 408576698