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

Side by Side Diff: chrome/browser/predictors/resource_prefetch_predictor_browsertest.cc

Issue 2545483002: predictors: Delete unnecessary parameter from RequestHandler (Closed)
Patch Set: Created 4 years 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 4
5 #include "base/command_line.h" 5 #include "base/command_line.h"
6 #include "chrome/browser/predictors/resource_prefetch_predictor.h" 6 #include "chrome/browser/predictors/resource_prefetch_predictor.h"
7 #include "chrome/browser/predictors/resource_prefetch_predictor_factory.h" 7 #include "chrome/browser/predictors/resource_prefetch_predictor_factory.h"
8 #include "chrome/browser/predictors/resource_prefetch_predictor_test_util.h" 8 #include "chrome/browser/predictors/resource_prefetch_predictor_test_util.h"
9 #include "chrome/browser/profiles/profile.h" 9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/ui/browser.h" 10 #include "chrome/browser/ui/browser.h"
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 protected: 128 protected:
129 using URLRequestSummary = ResourcePrefetchPredictor::URLRequestSummary; 129 using URLRequestSummary = ResourcePrefetchPredictor::URLRequestSummary;
130 130
131 void SetUpCommandLine(base::CommandLine* command_line) override { 131 void SetUpCommandLine(base::CommandLine* command_line) override {
132 command_line->AppendSwitchASCII( 132 command_line->AppendSwitchASCII(
133 switches::kSpeculativeResourcePrefetching, 133 switches::kSpeculativeResourcePrefetching,
134 switches::kSpeculativeResourcePrefetchingEnabled); 134 switches::kSpeculativeResourcePrefetchingEnabled);
135 } 135 }
136 136
137 void SetUpOnMainThread() override { 137 void SetUpOnMainThread() override {
138 embedded_test_server()->RegisterRequestHandler(base::Bind( 138 embedded_test_server()->RegisterRequestHandler(
139 &ResourcePrefetchPredictorBrowserTest::HandleRedirectRequest, 139 base::Bind(&ResourcePrefetchPredictorBrowserTest::HandleRedirectRequest,
140 base::Unretained(this), base::Unretained(embedded_test_server()))); 140 base::Unretained(this)));
141 embedded_test_server()->RegisterRequestHandler(base::Bind( 141 embedded_test_server()->RegisterRequestHandler(
142 &ResourcePrefetchPredictorBrowserTest::HandleResourceRequest, 142 base::Bind(&ResourcePrefetchPredictorBrowserTest::HandleResourceRequest,
143 base::Unretained(this), base::Unretained(embedded_test_server()))); 143 base::Unretained(this)));
144 ASSERT_TRUE(embedded_test_server()->Start()); 144 ASSERT_TRUE(embedded_test_server()->Start());
145 predictor_ = 145 predictor_ =
146 ResourcePrefetchPredictorFactory::GetForProfile(browser()->profile()); 146 ResourcePrefetchPredictorFactory::GetForProfile(browser()->profile());
147 ASSERT_TRUE(predictor_); 147 ASSERT_TRUE(predictor_);
148 EnsurePredictorInitialized(); 148 EnsurePredictorInitialized();
149 } 149 }
150 150
151 void NavigateToURLAndCheckSubresources(const GURL& main_frame_url) { 151 void NavigateToURLAndCheckSubresources(const GURL& main_frame_url) {
152 GURL endpoint_url = GetRedirectEndpoint(main_frame_url); 152 GURL endpoint_url = GetRedirectEndpoint(main_frame_url);
153 std::vector<URLRequestSummary> url_request_summaries; 153 std::vector<URLRequestSummary> url_request_summaries;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 } 197 }
198 198
199 void EnableHttpsServer() { 199 void EnableHttpsServer() {
200 ASSERT_FALSE(https_server_); 200 ASSERT_FALSE(https_server_);
201 https_server_ = base::MakeUnique<net::EmbeddedTestServer>( 201 https_server_ = base::MakeUnique<net::EmbeddedTestServer>(
202 net::EmbeddedTestServer::TYPE_HTTPS); 202 net::EmbeddedTestServer::TYPE_HTTPS);
203 https_server()->AddDefaultHandlers( 203 https_server()->AddDefaultHandlers(
204 base::FilePath(FILE_PATH_LITERAL("chrome/test/data"))); 204 base::FilePath(FILE_PATH_LITERAL("chrome/test/data")));
205 https_server()->RegisterRequestHandler( 205 https_server()->RegisterRequestHandler(
206 base::Bind(&ResourcePrefetchPredictorBrowserTest::HandleRedirectRequest, 206 base::Bind(&ResourcePrefetchPredictorBrowserTest::HandleRedirectRequest,
207 base::Unretained(this), base::Unretained(https_server()))); 207 base::Unretained(this)));
208 https_server()->RegisterRequestHandler( 208 https_server()->RegisterRequestHandler(
209 base::Bind(&ResourcePrefetchPredictorBrowserTest::HandleResourceRequest, 209 base::Bind(&ResourcePrefetchPredictorBrowserTest::HandleResourceRequest,
210 base::Unretained(this), base::Unretained(https_server()))); 210 base::Unretained(this)));
211 ASSERT_TRUE(https_server()->Start()); 211 ASSERT_TRUE(https_server()->Start());
212 } 212 }
213 213
214 // Returns the embedded test server working over HTTPS. Must be enabled by 214 // Returns the embedded test server working over HTTPS. Must be enabled by
215 // calling EnableHttpsServer() before use. 215 // calling EnableHttpsServer() before use.
216 const net::EmbeddedTestServer* https_server() const { 216 const net::EmbeddedTestServer* https_server() const {
217 return https_server_.get(); 217 return https_server_.get();
218 } 218 }
219 219
220 net::EmbeddedTestServer* https_server() { return https_server_.get(); } 220 net::EmbeddedTestServer* https_server() { return https_server_.get(); }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 while (true) { 254 while (true) {
255 auto it = redirects_.find(current); 255 auto it = redirects_.find(current);
256 if (it == redirects_.end()) 256 if (it == redirects_.end())
257 break; 257 break;
258 current = it->second.url; 258 current = it->second.url;
259 } 259 }
260 return current; 260 return current;
261 } 261 }
262 262
263 std::unique_ptr<net::test_server::HttpResponse> HandleResourceRequest( 263 std::unique_ptr<net::test_server::HttpResponse> HandleResourceRequest(
264 const net::test_server::EmbeddedTestServer* server,
265 const net::test_server::HttpRequest& request) const { 264 const net::test_server::HttpRequest& request) const {
266 auto resource_it = resources_.find(server->GetURL(request.relative_url)); 265 auto resource_it = resources_.find(request.GetURL());
267 if (resource_it == resources_.end()) 266 if (resource_it == resources_.end())
268 return nullptr; 267 return nullptr;
269 268
270 const ResourceSummary& summary = resource_it->second; 269 const ResourceSummary& summary = resource_it->second;
271 auto http_response = 270 auto http_response =
272 base::MakeUnique<net::test_server::BasicHttpResponse>(); 271 base::MakeUnique<net::test_server::BasicHttpResponse>();
273 http_response->set_code(net::HTTP_OK); 272 http_response->set_code(net::HTTP_OK);
274 if (!summary.request.mime_type.empty()) 273 if (!summary.request.mime_type.empty())
275 http_response->set_content_type(summary.request.mime_type); 274 http_response->set_content_type(summary.request.mime_type);
276 if (!summary.content.empty()) 275 if (!summary.content.empty())
277 http_response->set_content(summary.content); 276 http_response->set_content(summary.content);
278 if (summary.is_no_store) 277 if (summary.is_no_store)
279 http_response->AddCustomHeader("Cache-Control", "no-store"); 278 http_response->AddCustomHeader("Cache-Control", "no-store");
280 if (summary.request.has_validators) { 279 if (summary.request.has_validators) {
281 http_response->AddCustomHeader( 280 http_response->AddCustomHeader(
282 "ETag", base::StringPrintf("'%zu%s'", summary.version, 281 "ETag", base::StringPrintf("'%zu%s'", summary.version,
283 request.relative_url.c_str())); 282 request.relative_url.c_str()));
284 } 283 }
285 if (summary.request.always_revalidate) 284 if (summary.request.always_revalidate)
286 http_response->AddCustomHeader("Cache-Control", "no-cache"); 285 http_response->AddCustomHeader("Cache-Control", "no-cache");
287 else 286 else
288 http_response->AddCustomHeader("Cache-Control", "max-age=2147483648"); 287 http_response->AddCustomHeader("Cache-Control", "max-age=2147483648");
289 return std::move(http_response); 288 return std::move(http_response);
290 } 289 }
291 290
292 std::unique_ptr<net::test_server::HttpResponse> HandleRedirectRequest( 291 std::unique_ptr<net::test_server::HttpResponse> HandleRedirectRequest(
293 const net::test_server::EmbeddedTestServer* server,
294 const net::test_server::HttpRequest& request) const { 292 const net::test_server::HttpRequest& request) const {
295 auto redirect_it = redirects_.find(server->GetURL(request.relative_url)); 293 auto redirect_it = redirects_.find(request.GetURL());
296 if (redirect_it == redirects_.end()) 294 if (redirect_it == redirects_.end())
297 return nullptr; 295 return nullptr;
298 296
299 auto http_response = 297 auto http_response =
300 base::MakeUnique<net::test_server::BasicHttpResponse>(); 298 base::MakeUnique<net::test_server::BasicHttpResponse>();
301 http_response->set_code(redirect_it->second.code); 299 http_response->set_code(redirect_it->second.code);
302 http_response->AddCustomHeader("Location", redirect_it->second.url.spec()); 300 http_response->AddCustomHeader("Location", redirect_it->second.url.spec());
303 return std::move(http_response); 301 return std::move(http_response);
304 } 302 }
305 303
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 AddResource(https_server()->GetURL(kStylePath), 364 AddResource(https_server()->GetURL(kStylePath),
367 content::RESOURCE_TYPE_STYLESHEET, net::HIGHEST); 365 content::RESOURCE_TYPE_STYLESHEET, net::HIGHEST);
368 AddResource(https_server()->GetURL(kScriptPath), 366 AddResource(https_server()->GetURL(kScriptPath),
369 content::RESOURCE_TYPE_SCRIPT, net::MEDIUM); 367 content::RESOURCE_TYPE_SCRIPT, net::MEDIUM);
370 AddResource(https_server()->GetURL(kFontPath), 368 AddResource(https_server()->GetURL(kFontPath),
371 content::RESOURCE_TYPE_FONT_RESOURCE, net::HIGHEST); 369 content::RESOURCE_TYPE_FONT_RESOURCE, net::HIGHEST);
372 NavigateToURLAndCheckSubresources(GetURL(kRedirectPath)); 370 NavigateToURLAndCheckSubresources(GetURL(kRedirectPath));
373 } 371 }
374 372
375 } // namespace predictors 373 } // namespace predictors
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698