Commit 79bec1a8 authored by Doug Turner's avatar Doug Turner Committed by Commit Bot

Move mock.failed.request handling to the URLLoaderInterceptor::Interceptor

http://mock.failed.request is a special testing url load which allows us to
simulate error codes. The implementation is suppose to return the error code
referenced in the query part of the request to OnComplete().

This CL moves this handling from one of the ErrorPageTests to the
URLLoaderInterceptor::Interceptor class so that it can be shared.

Bug: 776589
Change-Id: Id6da78e4a3e62b9165d2fe30876b7bbafcf0e8b0
Reviewed-on: https://chromium-review.googlesource.com/847916
Commit-Queue: Doug Turner <dougt@chromium.org>
Reviewed-by: default avatarJohn Abd-El-Malek <jam@chromium.org>
Cr-Commit-Position: refs/heads/master@{#526852}
parent 67f55bd1
......@@ -464,24 +464,6 @@ class DNSErrorPageTest : public ErrorPageTest {
base::BindRepeating(
[](DNSErrorPageTest* owner,
content::URLLoaderInterceptor::RequestParams* params) {
// Handle mock failed request. The error code is embedded in the
// query. Here we strip it out, and call OnComplete with it.
// TODO(dougt) mock.failed.request handling can be moved into the
// URLLoaderInterceptor implementation so that we can share this
// with other tests.
if (params->url_request.url.GetWithEmptyPath().spec() ==
"http://mock.failed.request/") {
std::string query = params->url_request.url.query();
std::string error_code = query.substr(query.find("=") + 1);
int error = 0;
base::StringToInt(error_code, &error);
network::URLLoaderCompletionStatus status;
status.error_code = error;
params->client->OnComplete(status);
return true;
}
// Add an interceptor that serves LinkDoctor responses
if (google_util::LinkDoctorBaseURL() == params->url_request.url) {
// Send RequestCreated so that anyone blocking on
......
......@@ -50,10 +50,24 @@ class URLLoaderInterceptor::Interceptor : public mojom::URLLoaderFactory {
params.client = std::move(client);
params.traffic_annotation = traffic_annotation;
// We don't intercept the blob URL for plznavigate requests.
if (url_request.resource_body_stream_url.is_empty() &&
if (params.url_request.resource_body_stream_url.is_empty() &&
parent_->callback_.Run(&params))
return;
// mock.failed.request is a special request whereby the query indicates what
// error code to respond with.
if (params.url_request.url.DomainIs("mock.failed.request")) {
std::string query = params.url_request.url.query();
std::string error_code = query.substr(query.find("=") + 1);
int error = 0;
base::StringToInt(error_code, &error);
network::URLLoaderCompletionStatus status;
status.error_code = error;
params.client->OnComplete(status);
return;
}
original_factory_getter_.Run()->CreateLoaderAndStart(
std::move(params.request), params.routing_id, params.request_id,
params.options, std::move(params.url_request), std::move(params.client),
......@@ -144,7 +158,7 @@ URLLoaderInterceptor::URLLoaderInterceptor(const InterceptCallback& callback,
DCHECK(!BrowserThread::IsThreadInitialized(BrowserThread::UI) ||
BrowserThread::CurrentlyOn(BrowserThread::UI));
if (intercept_subresources &&
if (intercept_subresources_ &&
base::FeatureList::IsEnabled(features::kNetworkService)) {
RenderFrameHostImpl::SetNetworkFactoryForTesting(base::BindRepeating(
&URLLoaderInterceptor::CreateURLLoaderFactoryForSubresources,
......
......@@ -22,6 +22,9 @@ class URLLoaderFactoryGetter;
// -at ResourceMessageFilter for non network-service code path
// -by sending renderer an intermediate URLLoaderFactory for network-service
// codepath, as that normally routes directly to the network process
// -http(s)://mock.failed.request/foo URLs internally, copying the behavior
// of net::URLRequestFailedJob
//
// Notes:
// -intercepting frame requests doesn't work yet for non network-service case
// (will work once http://crbug.com/747130 is fixed)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment