chromium/content/browser/loader/navigation_early_hints_browsertest.cc

// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#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[] =;

// Listens to sockets on an EmbeddedTestServer for preconnect tests. Created
// on the UI thread. EmbeddedTestServerConnectionListener methods are called
// from a different thread than the UI thread.
class PreconnectListener
    : public net::test_server::EmbeddedTestServerConnectionListener {};

}  // namespace

// Most tests use EmbeddedTestServer but this uses QuicSimpleTestServer because
// Early Hints are only plumbed over HTTP/2 or HTTP/3 (QUIC).
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) {}

// Test that network isolation key is set correctly for Early Hints preload.
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 {};

// Tests that Early Hints preload is blocked when hints comes from the public
// network but a hinted resource is located in a private network.
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) {}

}  // namespace

class NavigationEarlyHintsHttp1Test : public ContentBrowserTest,
                                      public testing::WithParamInterface<bool> {};

INSTANTIATE_TEST_SUITE_P();

// Tests that Early Hints are allowed or disallowed on HTTP/1.1 based on a
// feature flag.
IN_PROC_BROWSER_TEST_P(NavigationEarlyHintsHttp1Test, AllowEarlyHints) {}

}  // namespace content