Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/public/test/browser_test_utils.h" | 5 #include "content/public/test/browser_test_utils.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/auto_reset.h" | 10 #include "base/auto_reset.h" |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 284 net::CookieStore* cookie_store = | 284 net::CookieStore* cookie_store = |
| 285 context_getter->GetURLRequestContext()->cookie_store(); | 285 context_getter->GetURLRequestContext()->cookie_store(); |
| 286 cookie_store->SetCookieWithOptionsAsync( | 286 cookie_store->SetCookieWithOptionsAsync( |
| 287 url, value, net::CookieOptions(), | 287 url, value, net::CookieOptions(), |
| 288 base::Bind(&SetCookieCallback, result, event)); | 288 base::Bind(&SetCookieCallback, result, event)); |
| 289 } | 289 } |
| 290 | 290 |
| 291 std::unique_ptr<net::test_server::HttpResponse> | 291 std::unique_ptr<net::test_server::HttpResponse> |
| 292 CrossSiteRedirectResponseHandler(const GURL& server_base_url, | 292 CrossSiteRedirectResponseHandler(const GURL& server_base_url, |
| 293 const net::test_server::HttpRequest& request) { | 293 const net::test_server::HttpRequest& request) { |
| 294 std::string prefix("/cross-site/"); | 294 net::HttpStatusCode http_status_code; |
| 295 if (!base::StartsWith(request.relative_url, prefix, | 295 |
| 296 base::CompareCase::SENSITIVE)) | 296 // Inspect the prefix and extract the remainder of the url into |params|. |
| 297 size_t length_of_chosen_prefix; | |
| 298 std::string prefix_302("/cross-site/"); | |
| 299 std::string prefix_307("/cross-site-307/"); | |
| 300 if (base::StartsWith(request.relative_url, prefix_302, | |
| 301 base::CompareCase::SENSITIVE)) { | |
| 302 http_status_code = net::HTTP_MOVED_PERMANENTLY; | |
| 303 length_of_chosen_prefix = prefix_302.length(); | |
| 304 } else if (base::StartsWith(request.relative_url, prefix_307, | |
| 305 base::CompareCase::SENSITIVE)) { | |
|
Charlie Reis
2016/05/24 20:49:53
nit: Wrong indent.
Łukasz Anforowicz
2016/05/24 21:05:19
Done (via git cl format).
| |
| 306 http_status_code = net::HTTP_TEMPORARY_REDIRECT; | |
| 307 length_of_chosen_prefix = prefix_307.length(); | |
| 308 } else { | |
| 309 // Unrecognized prefix - let somebody else handle this request. | |
| 297 return std::unique_ptr<net::test_server::HttpResponse>(); | 310 return std::unique_ptr<net::test_server::HttpResponse>(); |
| 298 | 311 } |
| 299 std::string params = request.relative_url.substr(prefix.length()); | 312 std::string params = request.relative_url.substr(length_of_chosen_prefix); |
| 300 | 313 |
| 301 // A hostname to redirect to must be included in the URL, therefore at least | 314 // A hostname to redirect to must be included in the URL, therefore at least |
| 302 // one '/' character is expected. | 315 // one '/' character is expected. |
| 303 size_t slash = params.find('/'); | 316 size_t slash = params.find('/'); |
| 304 if (slash == std::string::npos) | 317 if (slash == std::string::npos) |
| 305 return std::unique_ptr<net::test_server::HttpResponse>(); | 318 return std::unique_ptr<net::test_server::HttpResponse>(); |
| 306 | 319 |
| 307 // Replace the host of the URL with the one passed in the URL. | 320 // Replace the host of the URL with the one passed in the URL. |
| 308 GURL::Replacements replace_host; | 321 GURL::Replacements replace_host; |
| 309 replace_host.SetHostStr(base::StringPiece(params).substr(0, slash)); | 322 replace_host.SetHostStr(base::StringPiece(params).substr(0, slash)); |
| 310 GURL redirect_server = server_base_url.ReplaceComponents(replace_host); | 323 GURL redirect_server = server_base_url.ReplaceComponents(replace_host); |
| 311 | 324 |
| 312 // Append the real part of the path to the new URL. | 325 // Append the real part of the path to the new URL. |
| 313 std::string path = params.substr(slash + 1); | 326 std::string path = params.substr(slash + 1); |
| 314 GURL redirect_target(redirect_server.Resolve(path)); | 327 GURL redirect_target(redirect_server.Resolve(path)); |
| 315 DCHECK(redirect_target.is_valid()); | 328 DCHECK(redirect_target.is_valid()); |
| 316 | 329 |
| 317 std::unique_ptr<net::test_server::BasicHttpResponse> http_response( | 330 std::unique_ptr<net::test_server::BasicHttpResponse> http_response( |
| 318 new net::test_server::BasicHttpResponse); | 331 new net::test_server::BasicHttpResponse); |
| 319 http_response->set_code(net::HTTP_MOVED_PERMANENTLY); | 332 http_response->set_code(http_status_code); |
| 320 http_response->AddCustomHeader("Location", redirect_target.spec()); | 333 http_response->AddCustomHeader("Location", redirect_target.spec()); |
| 321 return std::move(http_response); | 334 return std::move(http_response); |
| 322 } | 335 } |
| 323 | 336 |
| 324 } // namespace | 337 } // namespace |
| 325 | 338 |
| 326 bool NavigateIframeToURL(WebContents* web_contents, | 339 bool NavigateIframeToURL(WebContents* web_contents, |
| 327 std::string iframe_id, | 340 std::string iframe_id, |
| 328 const GURL& url) { | 341 const GURL& url) { |
| 329 std::string script = base::StringPrintf( | 342 std::string script = base::StringPrintf( |
| (...skipping 912 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1242 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1255 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 1243 if (ack_result_ != INPUT_EVENT_ACK_STATE_UNKNOWN) | 1256 if (ack_result_ != INPUT_EVENT_ACK_STATE_UNKNOWN) |
| 1244 return ack_result_; | 1257 return ack_result_; |
| 1245 base::RunLoop run_loop; | 1258 base::RunLoop run_loop; |
| 1246 base::AutoReset<base::Closure> reset_quit(&quit_, run_loop.QuitClosure()); | 1259 base::AutoReset<base::Closure> reset_quit(&quit_, run_loop.QuitClosure()); |
| 1247 run_loop.Run(); | 1260 run_loop.Run(); |
| 1248 return ack_result_; | 1261 return ack_result_; |
| 1249 } | 1262 } |
| 1250 | 1263 |
| 1251 } // namespace content | 1264 } // namespace content |
| OLD | NEW |