// Copyright 2017 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef CONTENT_PUBLIC_TEST_URL_LOADER_INTERCEPTOR_H_ #define CONTENT_PUBLIC_TEST_URL_LOADER_INTERCEPTOR_H_ #include <memory> #include <optional> #include <set> #include <string> #include <string_view> #include "base/files/file_path.h" #include "base/functional/callback_helpers.h" #include "base/memory/scoped_refptr.h" #include "base/synchronization/lock.h" #include "mojo/public/cpp/bindings/pending_receiver.h" #include "mojo/public/cpp/bindings/remote.h" #include "net/base/net_errors.h" #include "net/http/http_request_headers.h" #include "net/traffic_annotation/network_traffic_annotation.h" #include "services/network/public/cpp/resource_request.h" #include "services/network/public/mojom/url_loader.mojom.h" namespace network { class URLLoaderFactoryBuilder; } // namespace network namespace content { // Helper class to intercept URLLoaderFactory calls for tests. // This intercepts: // -frame requests (which start from the browser) // -subresource requests from pages, dedicated workers, and shared workers // -by sending the renderer an intermediate URLLoaderFactory // -subresource requests from service workers and requests of non-installed // service worker scripts // -at EmbeddedWorkerInstance // -requests by the browser // -http(s)://mock.failed.request/foo URLs internally, copying the behavior // of net::URLRequestFailedJob // // Prefer not to use this class. In order of ease of use & simplicity: // -if you need to serve static data, use net::test::EmbeddedTestServer and // serve data from the source tree (e.g. in content/test/data). // -if you need to control the response data at runtime, then use // net::test_server::EmbeddedTestServer::RegisterRequestHandler. // -if you need to delay when the server sends the response, use // net::test_server::ControllableHttpResponse. // -otherwise, if you need full control over the net::Error and/or want to // inspect and/or modify the C++ structs used by URLLoader interface, then use // this helper class. // // Notes: // -the callback is called on the UI or IO threads depending on the factory // that was hooked // -this is done to avoid changing message order // -intercepting resource requests for subresources changes message order by // definition (since they would normally go directly from renderer->network // service, but now they're routed through the browser). class URLLoaderInterceptor { … }; } // namespace content #endif // CONTENT_PUBLIC_TEST_URL_LOADER_INTERCEPTOR_H_