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: chrome/browser/predictors/loading_test_util.h

Issue 2896713003: Create LoadingDataCollector class and have observers rely on it instead of ResourcePrefetchPredictor (Closed)
Patch Set: Rebase, merge loading_stats_collector. Created 3 years, 6 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 #ifndef CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCH_PREDICTOR_TEST_UTIL_H_ 4 #ifndef CHROME_BROWSER_PREDICTORS_LOADING_TEST_UTIL_H_
5 #define CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCH_PREDICTOR_TEST_UTIL_H_ 5 #define CHROME_BROWSER_PREDICTORS_LOADING_TEST_UTIL_H_
6 6
7 #include <memory>
7 #include <set> 8 #include <set>
8 #include <string> 9 #include <string>
9 #include <vector> 10 #include <vector>
10 11
11 #include "chrome/browser/predictors/resource_prefetch_predictor.h" 12 #include "chrome/browser/predictors/resource_prefetch_predictor.h"
12 #include "chrome/browser/predictors/resource_prefetch_predictor_tables.h" 13 #include "chrome/browser/predictors/resource_prefetch_predictor_tables.h"
13 #include "components/sessions/core/session_id.h" 14 #include "components/sessions/core/session_id.h"
15 #include "net/url_request/url_request_context.h"
16 #include "net/url_request/url_request_job.h"
17 #include "net/url_request/url_request_job_factory.h"
18 #include "net/url_request/url_request_test_util.h"
14 #include "testing/gmock/include/gmock/gmock.h" 19 #include "testing/gmock/include/gmock/gmock.h"
15 20
16 namespace predictors { 21 namespace predictors {
17 22
18 // Does nothing, controls which URLs are prefetchable. 23 // Does nothing, controls which URLs are prefetchable.
19 class MockResourcePrefetchPredictor : public ResourcePrefetchPredictor { 24 class MockResourcePrefetchPredictor : public ResourcePrefetchPredictor {
20 public: 25 public:
21 MockResourcePrefetchPredictor(const LoadingPredictorConfig& config, 26 MockResourcePrefetchPredictor(const LoadingPredictorConfig& config,
22 Profile* profile); 27 Profile* profile);
23 ~MockResourcePrefetchPredictor(); 28 ~MockResourcePrefetchPredictor();
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 const std::string& redirect_url = std::string(), 107 const std::string& redirect_url = std::string(),
103 bool has_validators = false, 108 bool has_validators = false,
104 bool always_revalidate = false); 109 bool always_revalidate = false);
105 110
106 ResourcePrefetchPredictor::Prediction CreatePrediction( 111 ResourcePrefetchPredictor::Prediction CreatePrediction(
107 const std::string& main_frame_key, 112 const std::string& main_frame_key,
108 std::vector<GURL> subresource_urls); 113 std::vector<GURL> subresource_urls);
109 114
110 void PopulateTestConfig(LoadingPredictorConfig* config, bool small_db = true); 115 void PopulateTestConfig(LoadingPredictorConfig* config, bool small_db = true);
111 116
117 class EmptyURLRequestDelegate : public net::URLRequest::Delegate {
118 void OnResponseStarted(net::URLRequest* request, int net_error) override {}
119 void OnReadCompleted(net::URLRequest* request, int bytes_read) override {}
120 };
121
122 scoped_refptr<net::HttpResponseHeaders> MakeResponseHeaders(
123 const char* headers);
124
125 class MockURLRequestJob : public net::URLRequestJob {
126 public:
127 MockURLRequestJob(net::URLRequest* request,
128 const net::HttpResponseInfo& response_info,
129 const std::string& mime_type);
130
131 bool GetMimeType(std::string* mime_type) const override;
132
133 protected:
134 void Start() override;
135 void GetResponseInfo(net::HttpResponseInfo* info) override;
136
137 private:
138 net::HttpResponseInfo response_info_;
139 std::string mime_type_;
140 };
141
142 class MockURLRequestJobFactory : public net::URLRequestJobFactory {
143 public:
144 MockURLRequestJobFactory();
145 ~MockURLRequestJobFactory() override;
146
147 void Reset();
148
149 net::URLRequestJob* MaybeCreateJobWithProtocolHandler(
150 const std::string& scheme,
151 net::URLRequest* request,
152 net::NetworkDelegate* network_delegate) const override;
153
154 net::URLRequestJob* MaybeInterceptRedirect(
155 net::URLRequest* request,
156 net::NetworkDelegate* network_delegate,
157 const GURL& location) const override;
158
159 net::URLRequestJob* MaybeInterceptResponse(
160 net::URLRequest* request,
161 net::NetworkDelegate* network_delegate) const override;
162
163 bool IsHandledProtocol(const std::string& scheme) const override;
164
165 bool IsSafeRedirectTarget(const GURL& location) const override;
166
167 void set_response_info(const net::HttpResponseInfo& response_info) {
168 response_info_ = response_info;
169 }
170
171 void set_mime_type(const std::string& mime_type) { mime_type_ = mime_type; }
172
173 private:
174 net::HttpResponseInfo response_info_;
175 std::string mime_type_;
176 };
177
178 std::unique_ptr<net::URLRequest> CreateURLRequest(
179 const net::TestURLRequestContext& url_request_context,
180 const GURL& url,
181 net::RequestPriority priority,
182 content::ResourceType resource_type,
183 bool is_main_frame);
184
112 // For printing failures nicely. 185 // For printing failures nicely.
113 std::ostream& operator<<(std::ostream& stream, const PrefetchData& data); 186 std::ostream& operator<<(std::ostream& stream, const PrefetchData& data);
114 std::ostream& operator<<(std::ostream& stream, const ResourceData& resource); 187 std::ostream& operator<<(std::ostream& stream, const ResourceData& resource);
115 std::ostream& operator<<(std::ostream& stream, const RedirectData& data); 188 std::ostream& operator<<(std::ostream& stream, const RedirectData& data);
116 std::ostream& operator<<(std::ostream& stream, const RedirectStat& redirect); 189 std::ostream& operator<<(std::ostream& stream, const RedirectStat& redirect);
117 std::ostream& operator<<( 190 std::ostream& operator<<(
118 std::ostream& stream, 191 std::ostream& stream,
119 const ResourcePrefetchPredictor::PageRequestSummary& summary); 192 const ResourcePrefetchPredictor::PageRequestSummary& summary);
120 std::ostream& operator<<( 193 std::ostream& operator<<(
121 std::ostream& stream, 194 std::ostream& stream,
(...skipping 21 matching lines...) Expand all
143 std::ostream& operator<<(std::ostream& stream, 216 std::ostream& operator<<(std::ostream& stream,
144 const PrecacheManifest& manifest); 217 const PrecacheManifest& manifest);
145 std::ostream& operator<<(std::ostream& stream, 218 std::ostream& operator<<(std::ostream& stream,
146 const PrecacheResource& resource); 219 const PrecacheResource& resource);
147 220
148 bool operator==(const PrecacheManifest& lhs, const PrecacheManifest& rhs); 221 bool operator==(const PrecacheManifest& lhs, const PrecacheManifest& rhs);
149 bool operator==(const PrecacheResource& lhs, const PrecacheResource& rhs); 222 bool operator==(const PrecacheResource& lhs, const PrecacheResource& rhs);
150 223
151 } // namespace precache 224 } // namespace precache
152 225
153 #endif // CHROME_BROWSER_PREDICTORS_RESOURCE_PREFETCH_PREDICTOR_TEST_UTIL_H_ 226 #endif // CHROME_BROWSER_PREDICTORS_LOADING_TEST_UTIL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698