#include "base/memory/weak_ptr.h"
#include "base/run_loop.h"
#include "base/strings/strcat.h"
#include "base/strings/string_split.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/task/sequenced_task_runner.h"
#include "base/task/single_thread_task_runner.h"
#include "base/test/bind.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h"
#include "base/threading/thread_restrictions.h"
#include "components/network_session_configurator/common/network_switches.h"
#include "content/browser/devtools/protocol/devtools_protocol_test_support.h"
#include "content/browser/loader/navigation_early_hints_manager.h"
#include "content/browser/renderer_host/render_frame_host_impl.h"
#include "content/browser/web_contents/web_contents_impl.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/content_browser_test.h"
#include "content/public/test/content_browser_test_utils.h"
#include "content/public/test/content_mock_cert_verifier.h"
#include "content/public/test/fenced_frame_test_util.h"
#include "content/public/test/prerender_test_util.h"
#include "content/public/test/test_navigation_observer.h"
#include "content/public/test/url_loader_interceptor.h"
#include "content/shell/browser/shell.h"
#include "content/test/content_browser_test_utils_internal.h"
#include "net/base/features.h"
#include "net/dns/mock_host_resolver.h"
#include "net/http/http_status_code.h"
#include "net/test/cert_test_util.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "net/test/embedded_test_server/embedded_test_server_connection_listener.h"
#include "net/test/embedded_test_server/http_request.h"
#include "net/test/embedded_test_server/http_response.h"
#include "net/test/quic_simple_test_server.h"
#include "net/test/test_data_directory.h"
#include "net/third_party/quiche/src/quiche/common/http/http_header_block.h"
#include "services/network/public/cpp/network_switches.h"
#include "services/network/public/mojom/early_hints.mojom.h"
#include "services/network/public/mojom/link_header.mojom.h"
namespace content {
PreloadedResources;
namespace {
struct HeaderField { … };
struct ResponseEntry { … };
const char kPageWithHintedScriptPath[] = …;
const char kPageWithHintedScriptBody[] = …;
const char kPageWithHintedCorsScriptPath[] = …;
const char kPageWithHintedCorsScriptBody[] = …;
const char kPageWithIframePath[] = …;
const char kPageWithIframeBody[] = …;
const char kPageWithHintedModuleScriptPath[] = …;
const char kPageWithHintedModuleScriptBody[] = …;
const char kHintedScriptPath[] = …;
const char kHintedScriptBody[] = …;
const char kHintedStylesheetPath[] = …;
const char kHintedStylesheetBody[] = …;
const char kEmptyPagePath[] = …;
const char kEmptyPageBody[] = …;
const char kRedirectedPagePath[] = …;
const char kRedirectedPageBody[] = …;
class PreconnectListener
: public net::test_server::EmbeddedTestServerConnectionListener { … };
}
class NavigationEarlyHintsTest : public DevToolsProtocolTest { … };
IN_PROC_BROWSER_TEST_F(NavigationEarlyHintsTest, Basic) { … }
IN_PROC_BROWSER_TEST_F(NavigationEarlyHintsTest, CorsAttribute) { … }
IN_PROC_BROWSER_TEST_F(NavigationEarlyHintsTest, ModulePreload) { … }
IN_PROC_BROWSER_TEST_F(NavigationEarlyHintsTest, DisallowPreloadFromIframe) { … }
IN_PROC_BROWSER_TEST_F(NavigationEarlyHintsTest, NavigationServerError) { … }
IN_PROC_BROWSER_TEST_F(NavigationEarlyHintsTest, RedirectSameOrigin) { … }
IN_PROC_BROWSER_TEST_F(NavigationEarlyHintsTest, RedirectCrossOrigin) { … }
IN_PROC_BROWSER_TEST_F(NavigationEarlyHintsTest, InvalidPreloadLink) { … }
IN_PROC_BROWSER_TEST_F(NavigationEarlyHintsTest, MultipleEarlyHints) { … }
const char kPageWithCrossOriginScriptPage[] = …;
IN_PROC_BROWSER_TEST_F(NavigationEarlyHintsTest, CORP_Pass) { … }
IN_PROC_BROWSER_TEST_F(NavigationEarlyHintsTest, CORP_Blocked) { … }
IN_PROC_BROWSER_TEST_F(NavigationEarlyHintsTest, COEP_Pass) { … }
IN_PROC_BROWSER_TEST_F(NavigationEarlyHintsTest, COEP_Block) { … }
IN_PROC_BROWSER_TEST_F(NavigationEarlyHintsTest, NetworkAnonymizationKey) { … }
IN_PROC_BROWSER_TEST_F(NavigationEarlyHintsTest, SimplePreconnect) { … }
IN_PROC_BROWSER_TEST_F(NavigationEarlyHintsTest, InvalidHeader_NewLine) { … }
IN_PROC_BROWSER_TEST_F(NavigationEarlyHintsTest, DevtoolsEventsForEarlyHint) { … }
class NavigationEarlyHintsAddressSpaceTest : public NavigationEarlyHintsTest { … };
IN_PROC_BROWSER_TEST_F(NavigationEarlyHintsAddressSpaceTest,
PublicToPrivateRequestBlocked) { … }
class NavigationEarlyHintsPrerenderTest : public NavigationEarlyHintsTest { … };
IN_PROC_BROWSER_TEST_F(NavigationEarlyHintsPrerenderTest,
AllowPreloadInPrerendering) { … }
class NavigationEarlyHintsFencedFrameTest : public NavigationEarlyHintsTest { … };
IN_PROC_BROWSER_TEST_F(NavigationEarlyHintsFencedFrameTest,
DisallowPreloadInFencedFrame) { … }
namespace {
const char kHttp1EarlyHintsPath[] = …;
class Http1EarlyHintsResponse : public net::test_server::HttpResponse { … };
std::unique_ptr<net::test_server::HttpResponse> HandleHttpEarlyHintsRequest(
const net::test_server::HttpRequest& request) { … }
}
class NavigationEarlyHintsHttp1Test : public ContentBrowserTest,
public testing::WithParamInterface<bool> { … };
INSTANTIATE_TEST_SUITE_P(…);
IN_PROC_BROWSER_TEST_P(NavigationEarlyHintsHttp1Test, AllowEarlyHints) { … }
}