#include <string>
#include "base/command_line.h"
#include "base/containers/contains.h"
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/ref_counted.h"
#include "base/metrics/statistics_recorder.h"
#include "base/run_loop.h"
#include "base/strings/escape.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_split.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/bind.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/simple_test_tick_clock.h"
#include "base/threading/platform_thread.h"
#include "base/timer/elapsed_timer.h"
#include "base/values.h"
#include "build/build_config.h"
#include "chrome/browser/browser_features.h"
#include "chrome/browser/browsing_data/chrome_browsing_data_remover_constants.h"
#include "chrome/browser/history/history_service_factory.h"
#include "chrome/browser/history/history_test_utils.h"
#include "chrome/browser/predictors/autocomplete_action_predictor.h"
#include "chrome/browser/predictors/autocomplete_action_predictor_factory.h"
#include "chrome/browser/preloading/chrome_preloading.h"
#include "chrome/browser/preloading/prefetch/no_state_prefetch/no_state_prefetch_test_utils.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/task_manager/task_manager_browsertest_util.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/location_bar/location_bar.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/test/base/ui_test_utils.h"
#include "components/content_settings/core/browser/cookie_settings.h"
#include "components/content_settings/core/common/features.h"
#include "components/content_settings/core/common/pref_names.h"
#include "components/embedder_support/switches.h"
#include "components/no_state_prefetch/browser/no_state_prefetch_handle.h"
#include "components/no_state_prefetch/browser/no_state_prefetch_manager.h"
#include "components/omnibox/browser/omnibox_edit_model.h"
#include "components/omnibox/browser/omnibox_view.h"
#include "components/prefs/pref_service.h"
#include "components/ukm/test_ukm_recorder.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/browsing_data_remover.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/storage_partition.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_contents_observer.h"
#include "content/public/common/content_features.h"
#include "content/public/common/content_switches.h"
#include "content/public/common/isolated_world_ids.h"
#include "content/public/common/result_codes.h"
#include "content/public/common/url_constants.h"
#include "content/public/test/back_forward_cache_util.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/browsing_data_remover_test_util.h"
#include "content/public/test/fenced_frame_test_util.h"
#include "content/public/test/no_renderer_crashes_assertion.h"
#include "content/public/test/preloading_test_util.h"
#include "content/public/test/prerender_test_util.h"
#include "content/public/test/url_loader_interceptor.h"
#include "content/public/test/url_loader_monitor.h"
#include "net/base/features.h"
#include "net/base/load_flags.h"
#include "net/base/request_priority.h"
#include "net/cookies/cookie_store.h"
#include "net/dns/mock_host_resolver.h"
#include "net/test/embedded_test_server/request_handler_util.h"
#include "net/test/scoped_mutually_exclusive_feature_list.h"
#include "services/metrics/public/cpp/ukm_builders.h"
#include "services/network/public/cpp/features.h"
#include "services/network/public/mojom/cookie_manager.mojom.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/common/chrome_debug_urls.h"
#include "third_party/blink/public/common/features.h"
namespace {
const char kExpectedPurposeHeaderOnPrefetch[] = …;
UkmEntry;
DestructionWaiter;
TestPrerender;
WaitForTaskManagerRows;
Preloading_Attempt;
std::string CreateServerRedirect(const std::string& dest_url) { … }
static constexpr char kOriginTrialPublicKeyForTesting[] = …;
enum class SplitCacheTestCase { … };
const struct { … } kTestCaseToFeatureMapping[] = …;
}
namespace prerender {
const char k302RedirectPage[] = …;
const char kPrefetchCookiePage[] = …;
const char kPrefetchFromSubframe[] = …;
const char kPrefetchImagePage[] = …;
const char kPrefetchJpeg[] = …;
const char kPrefetchLoaderPath[] = …;
const char kPrefetchLoopPage[] = …;
const char kPrefetchMetaCSP[] = …;
const char kPrefetchNostorePage[] = …;
const char kPrefetchPage[] = …;
const char kPrefetchPageWithFragment[] = …;
const char kPrefetchPage2[] = …;
const char kPrefetchPageBigger[] = …;
const char kPrefetchPageMultipleResourceTypes[] = …;
const char kPrefetchPng[] = …;
const char kPrefetchPng2[] = …;
const char kPrefetchPngRedirect[] = …;
const char kPrefetchRecursePage[] = …;
const char kPrefetchResponseHeaderCSP[] = …;
const char kPrefetchScript[] = …;
const char kPrefetchScript2[] = …;
const char kPrefetchCss[] = …;
const char kPrefetchFont[] = …;
const char kPrefetchDownloadFile[] = …;
const char kPrefetchSubresourceRedirectPage[] = …;
const char kServiceWorkerLoader[] = …;
const char kHungPrerenderPage[] = …;
class NavigationOrSwapObserver : public content::WebContentsObserver,
public TabStripModelObserver { … };
content::PreloadingFailureReason ToPreloadingFailureReasonFromFinalStatus(
FinalStatus status) { … }
class NewTabNavigationOrSwapObserver : public TabStripModelObserver,
public BrowserListObserver { … };
class NoStatePrefetchBrowserTest
: public test_utils::PrerenderInProcessBrowserTest { … };
class NoStatePrefetchBrowserTestHttpCache
: public NoStatePrefetchBrowserTest,
public testing::WithParamInterface<SplitCacheTestCase> { … };
class NoStatePrefetchBrowserTestHttpCacheDefaultAndAppendFrameOrigin
: public NoStatePrefetchBrowserTest { … };
IN_PROC_BROWSER_TEST_F(
NoStatePrefetchBrowserTestHttpCacheDefaultAndAppendFrameOrigin,
PrefetchTwoCrossOriginFrames) { … }
IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, PrefetchSimple) { … }
IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, PrefetchBigger) { … }
NoStatePrefetchBrowserTestHttpCacheDefaultAndDoubleKeyed;
IN_PROC_BROWSER_TEST_P(NoStatePrefetchBrowserTestHttpCacheDefaultAndDoubleKeyed,
LoadAfterPrefetch) { … }
IN_PROC_BROWSER_TEST_P(NoStatePrefetchBrowserTestHttpCacheDefaultAndDoubleKeyed,
LoadAfterPrefetchCrossOrigin) { … }
IN_PROC_BROWSER_TEST_P(NoStatePrefetchBrowserTestHttpCacheDefaultAndDoubleKeyed,
LoadAfterPrefetchCrossOriginRendererInitiated) { … }
INSTANTIATE_TEST_SUITE_P(…);
IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, PrefetchAllResourceTypes) { … }
class HTMLOnlyNoStatePrefetchBrowserTest : public NoStatePrefetchBrowserTest { … };
IN_PROC_BROWSER_TEST_F(HTMLOnlyNoStatePrefetchBrowserTest, PrefetchHTMLOnly) { … }
class HTMLCSSNoStatePrefetchBrowserTest : public NoStatePrefetchBrowserTest { … };
IN_PROC_BROWSER_TEST_F(HTMLCSSNoStatePrefetchBrowserTest, PrefetchHTMLCSS) { … }
class HTMLCSSSyncScriptNoStatePrefetchBrowserTest
: public NoStatePrefetchBrowserTest { … };
IN_PROC_BROWSER_TEST_F(HTMLCSSSyncScriptNoStatePrefetchBrowserTest,
PrefetchHTMLCSSSyncScript) { … }
class HTMLCSSSyncScriptFontNoStatePrefetchBrowserTest
: public NoStatePrefetchBrowserTest { … };
IN_PROC_BROWSER_TEST_F(HTMLCSSSyncScriptFontNoStatePrefetchBrowserTest,
PrefetchHTMLCSSSyncScript) { … }
class HTMLCSSScriptNoStatePrefetchBrowserTest
: public NoStatePrefetchBrowserTest { … };
IN_PROC_BROWSER_TEST_F(HTMLCSSScriptNoStatePrefetchBrowserTest,
PrefetchHTMLCSSScript) { … }
void GetCookieCallback(base::RepeatingClosure callback,
const net::CookieAccessResultList& cookie_list,
const net::CookieAccessResultList& excluded_cookies) { … }
IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, PrefetchCookie) { … }
IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, PrefetchCookieCrossDomain) { … }
IN_PROC_BROWSER_TEST_P(NoStatePrefetchBrowserTestHttpCacheDefaultAndDoubleKeyed,
PrefetchCookieCrossDomainSameSiteStrict) { … }
IN_PROC_BROWSER_TEST_P(NoStatePrefetchBrowserTestHttpCacheDefaultAndDoubleKeyed,
PrefetchCookieSameDomainSameSiteStrict) { … }
IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, PrefetchLoadFlag) { … }
IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, PurposeHeaderIsSet) { … }
IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest,
PurposeHeaderNotSetWhenNotPrefetching) { … }
IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, PrefetchImage) { … }
IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, PrefetchCrossDomain) { … }
IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest,
PrefetchFromCrossDomainSubframe) { … }
IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, ResponseHeaderCSP) { … }
IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, MetaTagCSP) { … }
IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, PrefetchMultipleRequest) { … }
IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, PrefetchSimultaneous) { … }
IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, NoPrefetchRecursive) { … }
IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, PrefetchNonexisting) { … }
IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, Prefetch301Redirect) { … }
IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest,
PrefetchRedirectUnsupportedScheme) { … }
IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, Prefetch302Redirect) { … }
IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, Prefetch301LoadFlags) { … }
IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, Prefetch301Subresource) { … }
IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, PrefetchClientRedirect) { … }
IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, PrefetchDownloadIframe) { … }
IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest,
PrefetchDownloadViaClientRedirect) { … }
IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, PrefetchPageWithFragment) { … }
IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, PrefetchCrx) { … }
IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, PrefetchHttps) { … }
IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, SSLError) { … }
IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, SSLSubresourceError) { … }
IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, Loop) { … }
#if BUILDFLAG(IS_WIN)
#define MAYBE_RendererCrash …
#else
#define MAYBE_RendererCrash …
#endif
IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, MAYBE_RendererCrash) { … }
IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, Png) { … }
IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, Jpeg) { … }
IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest,
PrerenderSafeBrowsingTopLevel) { … }
IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, ServerRedirect) { … }
IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, HistoryUntouchedByPrefetch) { … }
IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, IssuesIdlePriorityRequests) { … }
IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, ServiceWorkerIntercept) { … }
class NoStatePrefetchIncognitoBrowserTest : public NoStatePrefetchBrowserTest { … };
IN_PROC_BROWSER_TEST_F(NoStatePrefetchIncognitoBrowserTest,
PrerenderIncognito) { … }
IN_PROC_BROWSER_TEST_F(NoStatePrefetchIncognitoBrowserTest,
DISABLED_PrerenderIncognitoClosed) { … }
IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, ClearHistory) { … }
IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, ClearCache) { … }
IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, CancelAll) { … }
IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest,
CancelPrerenderWithPrerender) { … }
IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, PrerenderQuickQuit) { … }
IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, PrerenderClickNewWindow) { … }
IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest,
PrerenderClickNewForegroundTab) { … }
IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, PrerenderExcessiveMemory) { … }
IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, OpenTaskManager) { … }
IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest,
PrerenderHttpAuthentication) { … }
IN_PROC_BROWSER_TEST_F(NoStatePrefetchBrowserTest, PrerenderNoSSLReferrer) { … }
class SpeculationNoStatePrefetchBrowserTest
: public NoStatePrefetchBrowserTest { … };
IN_PROC_BROWSER_TEST_F(SpeculationNoStatePrefetchBrowserTest,
SpeculationPrefetch) { … }
IN_PROC_BROWSER_TEST_F(SpeculationNoStatePrefetchBrowserTest,
SpeculationDisallowsCrossOriginRedirect) { … }
IN_PROC_BROWSER_TEST_F(SpeculationNoStatePrefetchBrowserTest,
SpeculationAllowsSameOriginRedirectBlocked) { … }
IN_PROC_BROWSER_TEST_F(SpeculationNoStatePrefetchBrowserTest,
HungSpeculationTimedOutByNavigation) { … }
class NoStatePrefetchMPArchBrowserTest : public NoStatePrefetchBrowserTest { … };
class NoStatePrefetchPrerenderBrowserTest
: public NoStatePrefetchMPArchBrowserTest { … };
IN_PROC_BROWSER_TEST_F(NoStatePrefetchPrerenderBrowserTest,
ShouldNotRecordNavigation) { … }
class NoStatePrefetchFencedFrameBrowserTest
: public NoStatePrefetchMPArchBrowserTest { … };
IN_PROC_BROWSER_TEST_F(NoStatePrefetchFencedFrameBrowserTest,
ShouldNotRecordNavigation) { … }
}